1 | import { useContext, createContext } from 'react'
|
2 | import invariant from 'invariant'
|
3 |
|
4 | const MapContext = createContext<google.maps.Map | null>(null)
|
5 |
|
6 | export function useGoogleMap(): google.maps.Map | null {
|
7 | invariant(!!useContext, 'useGoogleMap is React hook and requires React version 16.8+')
|
8 |
|
9 | const map = useContext(MapContext)
|
10 |
|
11 | invariant(!!map, 'useGoogleMap needs a GoogleMap available up in the tree')
|
12 |
|
13 | return map
|
14 | }
|
15 |
|
16 | export default MapContext
|