Search code examples
next.jsreact-hooksreact-google-maps-api

useGoogleMap inside Next JS


Does anyone use useGoogleMap() inside NEXT JS component? It gives Unhandled Runtime Error Invariant Violation: useGoogleMap needs a GoogleMap available up in the tree error. I just need to refer to map of google Map inside Next JS.


Solution

  • you have to wrap the component that are using this hook by GoogleMap component as the documentation say:

    The GoogleMap component uses React Context internally to pass the map instance around. For the convenience the value is exposed with hook useGoogleMap (requires React 16.8+).