react-leaflet-markercluster is a dedicated React component that provides an intuitive wrapper for the popular Leaflet.markercluster plugin, designed specifically for use within react-leaflet applications. It addresses the common challenge of visualizing a large number of markers on a map by dynamically grouping them into clusters at various zoom levels, preventing clutter and improving map performance and user experience. The current stable release is v4.2.1, with v5.0.0-rc.0 currently in a release candidate phase to support React 19 and react-leaflet v5. The package aims for stability and compatibility with major react-leaflet versions, often releasing new major versions to align with its peer dependencies. Its primary differentiator is its seamless integration into the react-leaflet ecosystem, allowing developers to simply wrap existing Leaflet Marker components within a `<MarkerClusterGroup />` to enable clustering functionality without complex imperative Leaflet API calls, while also exposing full control over Leaflet.markercluster options via component props.
npm install react-leaflet-markerclusterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic Leaflet map with `react-leaflet` and enable marker clustering using `react-leaflet-markercluster`, showing multiple markers that group dynamically on zoom.
Upgrade peer dependencies (React, react-leaflet, leaflet, leaflet.markercluster) to their latest compatible versions as specified by react-leaflet-markercluster's package.json.
Refactor marker objects to use the 'position' key, e.g., `{ position: [lat, lng] }` instead of `{ lat, lng }`.Pass all Leaflet.markercluster options directly as props to the `<MarkerClusterGroup />` component instead of nesting them under an `options` prop.
Ensure `leaflet/dist/leaflet.css` and `react-leaflet-markercluster/styles` are imported at the root of your application, typically in a CSS file or directly in a JS entry point before your components render.
Install `leaflet.markercluster` using npm or yarn: `npm install leaflet.markercluster` or `yarn add leaflet.markercluster`.
Ensure `leaflet` and `leaflet.markercluster` peer dependencies are installed and properly imported/configured in your project before rendering React components that depend on them.
Verify your import statement to be `import MarkerClusterGroup from 'react-leaflet-markercluster';`.
Add `import 'leaflet/dist/leaflet.css';` and `import 'react-leaflet-markercluster/styles';` to your application's entry point (e.g., `App.tsx` or `index.ts`) or include them via HTML `<link>` tags.