google-map-react is an isomorphic React component that facilitates rendering custom React components directly onto a Google Map interface. Currently at version 2.2.5, the library maintains an active, though not rapid, release cadence, with recent updates ensuring compatibility with modern React versions, including React 19. Its primary differentiators include true isomorphic rendering capabilities, allowing server-side rendering for improved SEO, and the ability to render custom React components as markers or overlays on the map instead of relying solely on default Google Maps elements. Uniquely, it can calculate component positions on the map without immediate reliance on the full Google Maps API, which is loaded on demand only when the `GoogleMapReact` component is first used. This approach streamlines initial load times and provides a flexible way to integrate Google Maps into React applications.
npm install google-map-reactVerified import paths — ran on the pinned version, not inferred.
This code demonstrates how to set up a basic Google Map with a custom React component serving as a marker. It highlights the explicit container sizing requirement and the API key configuration.
Change `import { utilName } from 'google-map-react/utils'` to `import { utilName } from 'google-map-react'`.Ensure the parent container of `GoogleMapReact` has explicit `height` and `width` styles (e.g., `height: '100vh', width: '100%'`).
Add the prop `yesIWantToUseGoogleMapApiInternals={true}` to your `GoogleMapReact` component when using `onGoogleApiLoaded`.Ensure `bootstrapURLKeys.key` is populated with a valid Google Maps API key that has the Maps JavaScript API enabled and billing configured in the Google Cloud Console.
Migrate any custom React components interacting with the map to modern React lifecycle methods or hooks to avoid warnings in strict mode and future compatibility issues. Updates in 2.2.2 removed `findDOMNode` references, further modernizing the internal component structure.
Apply explicit CSS `width` and `height` properties to the `div` element that wraps the `GoogleMapReact` component.
Verify your `key` in `bootstrapURLKeys` is correct. Check the Google Cloud Console to ensure the Maps JavaScript API is enabled for your project and that a billing account is linked.
Ensure all custom components passed as children to `GoogleMapReact` are correctly defined and exported, and imported with the correct syntax (e.g., `export default MyComponent;` for default imports, `export { MyComponent };` for named imports).