React integration
The React package lets React describe deck.gl layers, views, widgets, and effects while deck.gl owns drawing. It provides a native React Fiber renderer for standalone Deck instances and external map overlays. It also keeps the former component API available at @deck.gl/react/legacy.
This page is part of Application integrations. For map host adapters, see Map renderer integrations. For other UI hosts, see Widgets and Jupyter and Python bindings.
Integration model
The package has two related surfaces. The package root exposes DOM-facing React components backed by the Fiber renderer, while the legacy subpath preserves the older DeckGL component and widget API. Both surfaces turn React state into updates for a deck.gl runtime rather than asking React to draw the visualization.
| Surface | Main role |
|---|---|
@deck.gl/react | Mount a standalone Deck through DeckGL, or build a compatible overlay component with createDeckGL. |
@deck.gl/react/reconciler | Create and manage a Fiber root directly for advanced integrations. |
@deck.gl/react/legacy | Retain the previous DeckGL, widget, hook, and context contract. |
| Wrapper entry points | Turn deck.gl classes into React components that emit native deck.gl elements. |
The root package does not select a map provider by itself. A provider-specific integration supplies an external overlay factory when it needs a map host, as described in Map renderer integrations.
Declarative descriptors
The Fiber tree describes deck.gl objects through native elements such as <deckLayer>, <deckView>, <deckWidget>, and <deckEffect>. The reconciler collects these descriptors from the committed tree, separates them by kind, and sends the resulting groups to the Deck or overlay instance.
Applications can also pass layers, views, widgets, and effects as root props. JSX descriptors and prop values are combined by category, with stable ids deciding which view, widget, or effect replaces another value. This permits gradual migration between prop-based and JSX-based composition.
flowchart LR
A[React tree and root props] --> B[Fiber root]
B --> C[Layers, views, widgets, effects]
C --> D[Standalone Deck or external overlay]
D --> E[Drawing, map coordination, and widget state]
References: modules/…/config.ts• L138-180 modules/…/config.ts• L564-631 modules/…/utils.ts• L246-286
Class wrappers
The wrapper factories provide the usual React component form for deck.gl classes. A layer, view, widget, or effect component creates its class instance from props and emits the matching native element, so application code can use typed JSX without changing the reconciler contract.
Layer and view wrappers keep their class type information. Widget and effect wrappers rely on deck.gl ids so the runtime can retain the matching DOM or effect state as React creates new descriptors.
References: modules/…/factories.tsx• L29-49 modules/…/factories.tsx• L61-73 modules/…/factories.tsx• L81-120
Fiber root lifecycle
The reconciler gives each mounted root one isolated state store and one deck.gl target. The root is configured with Deck props first, then React renders descriptors into it; later prop changes update the target without requiring a new React tree commit.
Root ownership
createRoot is idempotent for a root element. The first configuration chooses either a standalone Deck or an externally created overlay, and that choice remains bound to the root. render supplies the React tree, while unmountAtNode removes the tree, finalizes the target, clears root state, and removes the registry entry.
This ownership rule makes the mounted React root responsible for releasing the deck.gl resources that it created. An external map remains owned by its map integration, but the overlay instance still follows the React root lifetime.
References: modules/…/renderer.ts• L103-120 modules/…/renderer.ts• L143-195 modules/…/renderer.ts• L233-338 modules/…/store.ts• L91-118
Reconciliation updates
The renderer uses a persistent tree: React builds a new descriptor tree and commits it as a complete set. The renderer flattens that tree, groups its objects, and calls setProps on the active target. Deck.gl then applies its own id-based diff to determine the work needed for the visualization.
The root remembers the last committed JSX descriptors. This allows a later configuration-only update to combine new root props with the last React tree, so a change to a callback or other Deck prop does not discard layers or views.
References: modules/…/config.ts• L282-364 modules/…/config.ts• L473-631 modules/…/utils.ts• L63-143
DOM entry points
The DOM layer adapts the non-DOM Fiber renderer to a browser component. It creates the canvas and wrapper for a standalone Deck, or uses a detached root when the target is an external overlay. React owns the component lifecycle and DOM placement while the reconciler owns the deck.gl descriptor tree.
Standalone Deck roots
DeckGL creates a standalone Deck when no external overlay factory is supplied. The component can render its own canvas or use an application-owned canvas. Its width, height, and style define the wrapper and canvas relationship, so the canvas fills the root surface.
The component reports the target instance through ref and onDeckChange. Those handles are available after configuration and receive null during cleanup, which gives an application a controlled place for queries or other imperative work.
References: modules/…/components.tsx• L63-96 modules/…/components.tsx• L163-258 modules/…/components.tsx• L307-319 modules/…/react.ts• L19-31
External overlay roots
createDeckGL builds a React component around a provider-supplied overlay factory. The component renders the React tree into an internal detached root, so the overlay can draw through a host map without putting the overlay's rendering surface into the normal DOM tree.
The factory can request recreation when construction-only props change. The component finalizes the old overlay before it reports and exposes the new one, which keeps the instance lifecycle clear to the host integration.
References: modules/…/components.tsx• L98-132 modules/…/components.tsx• L219-283 modules/…/components.tsx• L321-352 modules/…/react.ts• L12-17
Map host synchronization
An external overlay needs two separate links to its host: the overlay instance must be attached to the current map, and the overlay must receive the view description that it can control. The DOM entry point keeps both links in React lifecycle order without passing the host map to deck.gl as an ordinary overlay prop.
Map attachment
An integration can provide an attach function when it creates an overlay component. The component calls it after an overlay and map are available, calls the returned detach function before replacement or finalization, and repeats the process when the map changes. The same pair must be safe during React effect replay.
Without attach, the application receives the overlay through onDeckChange and performs the host-specific attachment itself. This keeps map ownership in the provider integration while the React package owns overlay creation and cleanup.
References: modules/…/components.tsx• L121-131 modules/…/components.tsx• L197-205 modules/…/components.tsx• L260-301 modules/…/react.ts• L33-41
View forwarding
External overlays normally receive their views prop from the host integration. An integration can enable view forwarding when the overlay also supports <deckView> children; then JSX views are merged with prop views and sent to the overlay. If forwarding is disabled, JSX views stay out of the external overlay.
This boundary matters for map-backed views. It lets a host map keep its own camera model while still allowing integrations that support deck.gl view composition to opt into React-defined view regions. See Map renderer integrations for the provider-level behavior.
References: modules/…/components.tsx• L114-119 modules/…/components.tsx• L153-159 modules/…/utils.ts• L246-285 modules/…/store.ts• L27-32
Legacy component API
The previous component API remains available under @deck.gl/react/legacy so existing applications can keep the older React-to-Deck contract while the package root uses the Fiber renderer. The legacy entry point exports its DeckGL component together with the established widget components, useWidget, context type, and ref and prop types.
The legacy component owns one Deck instance for its mounted lifetime. It still supports JSX extraction for layers and views, React-managed DOM under views, widget registration, controlled or initial view state, and imperative picking through its ref. Its source now lives under modules/react/src/legacy, but its public subpath preserves the compatibility boundary.
References: modules/…/index.ts• L5-55 modules/…/deckgl.ts• L31-67 modules/…/deckgl.ts• L94-133 modules/…/deckgl.ts• L228-254 modules/…/package.json• L64-83
Public package paths
The package root exports the DOM surface. The legacy subpath exports the prior component surface, and provider and wrapper subpaths expose specialized integrations without changing the root's ownership model.
This split lets new code use Fiber roots and lets existing code retain legacy imports. It also prevents a provider package from being chosen implicitly when the application has not selected one.
References: modules/…/index.ts• L5-6 modules/…/index.ts• L6-21 modules/…/package.json• L64-125
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the root package and
legacysubpath exports aligned with the intended migration boundary. - Preserve one immutable rendering capability per root element. A root must not silently switch between standalone Deck and external overlay modes.
- Keep JSX descriptors and root props merged by category and id. In particular, preserve the rule that prop layers follow JSX layers and prop views replace JSX views with the same id.
- Keep
configureable to reapply the last committed JSX descriptors during prop-only updates. - Preserve external-overlay view forwarding as an explicit integration choice. Do not send JSX views to a map overlay that does not support them.
- Keep map detachment ahead of overlay finalization and make attach and detach safe during React Strict Mode effect replay.
- Preserve the
refandonDeckChangecleanup order so applications do not retain a finalized instance. - Keep native element names and class wrapper output synchronized. A wrapper that emits an unsupported or mismatched element cannot reach the reconciler.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
createRoot is called again for one element with a different overlay factory or forwarding mode. | The existing root keeps its first rendering capability, and the assertion rejects the mismatch. | Reuse one root configuration for each element. |
render runs before configure creates a target. | The React tree has no Deck or overlay instance to receive its descriptors. | Configure the root before rendering children. |
| A JSX view is used with an external overlay that does not forward views. | The overlay keeps only its views prop and ignores the JSX view. | Enable forwarding only for overlays that support React-defined views. |
| An attach callback does not detach before finalization or cannot handle effect replay. | The map can retain a finalized overlay or receive duplicate attachment calls. | Make attach and detach repeat-safe and detach before root unmount. |
| A canvas id or supplied canvas does not resolve to an HTML canvas. | DOM root setup asserts or cannot create a usable renderer target. | Mount the canvas before the effect configures the root. |
| A native element receives the wrong descriptor type or an unsupported element name. | The reconciler throws instead of producing a partial visualization. | Use the matching wrapper or pass a real Layer, View, Widget, or Effect. |
| A layer, view, widget, or effect lacks a stable id. | Deck.gl cannot reliably match the new descriptor to the prior one. | Assign stable ids to descriptors that persist across renders. |
Key files
| File | Why to read it |
|---|---|
| modules/…/index.ts | Shows the package-root export boundary for the new DOM and Fiber surface. |
| modules/…/components.tsx | Explains standalone roots, external overlays, canvas ownership, map attachment, and cleanup. |
| modules/…/renderer.ts | Shows root creation, configuration, rendering, idempotency, and unmount behavior. |
| modules/…/config.ts | Defines the native deck.gl elements and the commit from a React tree to Deck props. |
| modules/…/utils.ts | Defines descriptor grouping and the merge rules for JSX and root props. |
| modules/…/factories.tsx | Shows how deck.gl classes become typed React components. |
| modules/…/deckgl.ts | Shows the retained component API and its Deck lifecycle and React synchronization contract. |
| modules/…/index.ts | Lists the public legacy component, widget, hook, and type exports. |
| modules/…/package.json | Defines the public root, legacy, reconciler, provider, and wrapper package paths. |