The useMap()
hook can be used to directly access the google.maps.Map
instance created by a Map
component within the APIProvider
in your application.
When there is only a single map within the APIProvider
, the useMap()
hook can be called without any arguments and the Map
doesn't need an id.
The same is true for components that are added as a child to the Map
component.
const MyComponent = () => {
const map = useMap();
useEffect(() => {
if (!map) return;
}, [map]);
return <>...</>;
};
const App = () => {
return (
<APIProvider>
<Map></Map>
<MyComponent />
</APIProvider>
);
};
When there are multiple Map
components in the APIProvider
, they are only retrievable using the useMap()
hook when the hook is either called from a child-component of a Map
or when an explicit id is specified on both the map and as a parameter of the useMap()
hook.
The id of the map-instance to be returned. If not specified it will return the parent map instance, or the default map instance if there is no parent.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4