Introducing a new way to review your PRs.

Read the announcement

visgl / react-google-maps

React components and hooks for the Google Maps JavaScript API

View on GitHub

19 documents · Updated Nov 2, 2026

docs / package-exports-and-types

Package exports and type surfaces

@vis.gl/react-google-maps presents a React interface to the Google Maps JavaScript API through separate browser, 3D, and server-safe entry points. The package also publishes type support that makes Google Maps custom elements usable with React and keeps older 3D imports working while users move to the dedicated 3D entry point.

Public entry points

The package maps each supported import path to a matching runtime bundle and declaration file. Consumers should choose the entry point that matches the capability they need rather than reach into source modules.

flowchart LR
  App[Application] --> Root[Package root]
  App --> ThreeD[Package /3d entry point]
  App --> Server[Package /server entry point]
  Root --> TwoD[2D maps, shared hooks, static maps]
  ThreeD --> ThreeDCapabilities[3D maps and 3D overlays]
  Server --> ServerSafe[Static map rendering and URL creation]
Import pathMain purposeEnvironment fit
@vis.gl/react-google-maps2D maps, shared React map tools, static maps, and compatibility exportsBrowser applications
@vis.gl/react-google-maps/3d3D maps, 3D overlays, and the 3D map hookBrowser applications with 3D Maps support
@vis.gl/react-google-maps/serverStatic map capabilityServer code and server-rendered applications
@vis.gl/…/examples.cssExample styling assetApplications that use the published examples styles

Root entry point

The root entry point is the normal application surface for 2D maps. It combines the provider and map components with common overlays, hooks, map helpers, static map capability, and shared public constants. It also re-exports older 3D names for compatibility; new 3D code should use the dedicated entry point instead.

References: package.json• L13-18 src/index.ts• L1-26

3D entry point

The /3d entry point isolates the 3D product surface from the normal 2D surface. It gives applications one import boundary for 3D maps, 3D markers and overlays, 3D-specific types, and useMap3D, while still sharing the React type bridge used by the main package.

References: package.json• L24-27 src/…/index.ts• L1-15

Server entry point

The /server entry point is the server-safe package boundary. It exposes static map rendering and URL creation without making server code depend on the interactive browser map surface. See server-safe integration for the server workflow and its limits.

References: package.json• L19-23 src/…/index.ts• L1-3 src/…/static-map.tsx• L1-19

Export boundaries

The export boundaries separate interactive 2D maps, interactive 3D maps, and image-based static maps. This separation helps an application select a compatible runtime and keeps server code focused on work that does not require a live browser map.

2D export surface

The root surface supports the main React map model. Applications use it to provide the Maps API, render 2D maps and overlays, observe map state, and create static map images. The static map tools belong to this surface because they are also useful to browser applications, but they can be reached without the interactive map components through /server.

References: src/index.ts• L5-26 src/…/static-map.tsx• L3-19 src/…/types.ts• L1-37

3D export surface

The 3D surface supports the Google Maps 3D map model and its related elements. It includes the map and marker contexts, 3D map controls, 3D geometry and model elements, popovers, and the hook for finding a 3D map instance. These exports are grouped so an application can opt into 3D capabilities without treating them as part of the primary 2D surface.

For a product view of the 3D feature set, see three-dimensional maps.

References: src/…/index.ts• L5-15 src/…/index.tsx• L17-80 src/…/marker-3d.tsx• L19-60 src/…/popover.tsx• L18-60

Static map surface

The static map surface turns map options into a Google Static Maps URL and renders that URL as an image. URL creation accepts the map view plus optional markers, paths, visible locations, and style data. This makes static maps suitable for server output, previews, and pages that do not need a live Maps JavaScript API instance.

For the static map request model and server signing flow, see static maps.

References: src/…/static-map.tsx• L3-19 src/…/types.ts• L1-37

Compatibility exports

Compatibility exports preserve the old root import path while the package moves 3D names to /3d. They point to the same 3D values and types as the dedicated surface, so existing applications can migrate imports without changing the feature they use.

Deprecated root 3D exports

The root entry point re-exports 3D maps, markers, popovers, contexts, hooks, constants, and event types through a deprecated compatibility module. The deprecation message names @vis.gl/react-google-maps/3d as the replacement. New code should import 3D names from /3d; existing root imports remain a migration path rather than a separate API.

References: src/deprecated-3d-exports.ts• L1-119 src/index.ts• L14-15

Supplemental type declarations

The package adds type declarations around the Google Maps custom-element model so React code can use the same elements and properties with useful type checks. These declarations are part of the public type surface even when they do not add a separate runtime import.

React custom-element bridge

The React custom-element bridge maps Google Maps element properties and events into JSX types. It adds event handler names derived from Google Maps event maps and extends React's intrinsic elements and CSS property types. The root and 3D entry points include this bridge so their JSX usage has a consistent type model.

References: types/…/index.d.ts• L1-33 src/index.ts• L1-3 src/…/index.ts• L1-3

Writable Google Maps properties

The writable type declarations widen Google Maps values for React property updates. They allow setter-friendly forms such as literals, strings, iterables, and nullable values where the Maps API accepts them. The bridge uses these types to describe custom-element properties that React can write.

References: types/…/index.d.ts• L1-61 types/…/index.d.ts• L1-20

Global declarations

The global declarations provide the package-wide type support for the optional GOOGLE_MAPS_API_KEY value and CSS module imports. They support build and application type checks; they do not create a runtime configuration source.

References: types/…/index.d.ts• L1-5 tsconfig.json• L2-22

Import selection

The import choice follows the capability and execution environment. The next page to read for server code is server-safe integration; use three-dimensional maps for the 3D feature model and static maps for image-based map output.

NeedUse
Interactive 2D map or shared map hookRoot entry point
Interactive 3D map or 3D overlay/3d entry point
Static image or static map URL in server code/server entry point
Existing code with root 3D importsKeep working during migration, then move imports to /3d

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the package.json export paths aligned with the three Rollup entry names and their generated declaration files.
  • Keep the root and /3d type-bridge references aligned so JSX types do not differ by import path.
  • When moving a 3D export, update both the dedicated /3d surface and the deprecated root compatibility surface.
  • When changing static map exports, check both root consumers and server consumers because they share the same capability through different entry points.
  • Preserve the shared context relationship between root and /3d builds so an APIProvider from one boundary can serve a 3D map from the other.

Important failure modes

TriggerConsequenceGuard
A package export path does not match its generated bundle or declaration fileThe import fails at runtime or TypeScript cannot resolve the packageKeep package.json paths and the Rollup entry names in sync
Server code imports the root interactive map surfaceServer rendering reaches browser-only map behaviorUse @vis.gl/react-google-maps/server for static map work and keep interactive maps client-only
New 3D code imports from the deprecated root surfaceThe code depends on a compatibility path that may be removed laterImport 3D values and types from @vis.gl/react-google-maps/3d
The React custom-element bridge is not included in a public entryJSX event or property types become incomplete for consumersRetain the bridge type export and reference in both browser entry points

Key files

FileWhy to read it
package.jsonDefines the public package paths and their runtime and type targets.
src/index.tsShows the main 2D and shared export surface.
src/…/index.tsShows the dedicated 3D export surface.
src/…/index.tsShows the server-safe boundary.
src/deprecated-3d-exports.tsDefines the root compatibility layer for older 3D imports.
types/…/index.d.tsDefines the React JSX bridge for Google Maps custom elements.
types/…/index.d.tsDefines setter-friendly Google Maps property types.
rollup.config.mjsMaps source entry points to the published bundles and declarations.