React Leaflet
React components for Leaflet maps enabling interactive mapping in React applications.
3. Used by agents' projects
Dependency in 61 public GitHub projects set up for AI coding agents that we scanned (1.0%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What React Leaflet does
React Leaflet wraps Leaflet layers as React components without replacing Leaflet: Leaflet does the DOM rendering, and props are used to create Leaflet instances and are immutable by default.
React Leaflet popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How React Leaflet is used
- React Leaflet is a dependency in 61 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (1.3% of the 4,867 JavaScript/TypeScript ones), #4 of 63 in 3d and graphics.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 388; those are left out of every share on this page.
- The most used alternative in our scan is Mapbox GL (24 projects).
- Projects that use it most often also use Leaflet (95.1%), Lucide React (88.5%), clsx (80.3%).
By coding agent
Often used with
React Leaflet in practice
Strengths
React only renders the <code><div></code> for <code>MapContainer</code> and the contents of UI layer components. The docs say rendering the layers to the DOM "is done by Leaflet itself".
Unless stated otherwise, every exported component supports a ref that exposes the created Leaflet element instance. For panes, the ref exposes the DOM element. The docs say this gives access to Leaflet's imperative APIs when required.
When a child component renders again, the docs say changes to its supported mutable props are applied to the map. When it is removed from the render tree, it removes its layer from the map as needed.
The docs say a unique <code>key</code> on a <code>MapContainer</code> element can be set to reset it.
Watch out for
The docs say Leaflet makes direct calls to the DOM when it is loaded, and that React Leaflet is therefore not compatible with server-side rendering.
Props are used to create the Leaflet instance on the first render. The docs say they will not be updated in the UI when they change unless they are explicitly documented as mutable.
The docs say some properties can be updated through Leaflet's setters. Other components should be completely replaced by setting a unique value on their <code>key</code> property.
More about React Leaflet
Packages around it
- leaflet: Underlying map library
- lucide-react: Icon components
- clsx: className builder
- tailwind-merge: Tailwind class merging
- class-variance-authority: Component style variants
- @radix-ui: Headless UI primitives
More in 3D and graphics
Alternatives
React Leaflet This page
WebGL-based interactive maps library for rendering vector tiles and geospatial data.
React components for MapLibre GL and Mapbox GL for interactive maps.
Get started
Install it.
npm install react-leafletRules for your agent
## React Leaflet
- The docs say React Leaflet "is not compatible with server-side rendering" because Leaflet makes direct calls to the DOM when it is loaded. Account for this in SSR frameworks.
- Use other React Leaflet components and hooks only as descendants of a `MapContainer`.
- Treat component props as immutable by default. Only props explicitly documented as mutable are updated in the UI when they change.
- Mutable prop changes are compared by reference unless the docs state otherwise. They are applied by calling the relevant method on the Leaflet instance.
- For components that should be completely replaced, set a unique value on their `key` prop. To reset a whole map, set a unique `key` on `MapContainer`.
- Do not use React's `Activity` component with the map. The docs call it incompatible with how React Leaflet works.
- Use refs to Leaflet instances carefully, since imperative calls may create inconsistencies with props. For v5, React v19 is a required peer dependency and `LeafletProvider` is no longer in the core package.