-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix map unmounting in component lifecycle (#276)
- Loading branch information
1 parent
fadd145
commit 01b269b
Showing
7 changed files
with
116 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { createContext, useContext, useState } from 'react'; | ||
import { Map } from 'maplibre-gl'; | ||
|
||
interface MapContextProps { | ||
map: Map | null; | ||
setMap: React.Dispatch<React.SetStateAction<Map | null>>; | ||
} | ||
|
||
const MapContext = createContext<MapContextProps | undefined>(undefined); | ||
|
||
export const MapProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const [map, setMap] = useState<Map | null>(null); | ||
return ( | ||
<MapContext.Provider value={{ map, setMap }}> | ||
{children} | ||
</MapContext.Provider> | ||
); | ||
}; | ||
|
||
export const useMap = (): MapContextProps => { | ||
const context = useContext(MapContext); | ||
if (!context) { | ||
throw new Error('useMap must be used within a MapProvider'); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters