TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published


A hook for using Supercluster with React.

const { clusters, supercluster } = useSupercluster({
  points: [],
  bounds: [
  zoom: 12,
  options: { radius: 75, maxZoom: 20 }


You will need to install Supercluster as a peer dependency of this package.

yarn add supercluster use-supercluster


This package contains an example along with tests, but full examples with instructions in the most popular mapping libraries for React can be found below.


Full instructions and an example can be found here.

Google Maps

Full instructions and an example can be found here.


Full instructions and an example can be found here.


The 'options' property passed to useSupercluster supports Supercluster's options and additionally includes support for the disableRefresh option."

Map & Reduce Options

As an example, you can use map and reduce to keep track of a total value summed up from across the points. In this case we have the total cost, the max severity, plus another count (which is redundant because Supercluster gives us the point_count property).

const options = {
  radius: 75,
  maxZoom: 20,
  map: props => ({
    cost: props.cost,
    severity: props.severity,
    count: 1
  reduce: (acc, props) => {
    acc.count += 1;
    acc.cost += props.cost;
    acc.severity = Math.max(acc.severity, props.severity);
    return acc;

I found map and reduce a little confusing! The value returned from map of the first point is used as the initial value passed as the accumulator to the reduce function. The only props you have available in reduce are the ones returned from map. You technically don't need to return a value from reduce (it's not used), but instead need to mutate the accumulator object.

Then these accumulated properties can be used and are available on each cluster:

  { => {
    const properties = || {};
    if (properties.cluster) {
      return (
        <li key={}>
          <h2>Points: {properties.point_count}</h2>
          <p>Cost: {properties.cost.toFixed(2)}</p>
          <p>Severity: {properties.severity}</p>
          <p>Count: {properties.count}</p>
    } else {
      return <li key={properties.crimeId}>{properties.category}</li>;


With the disableRefresh option, clusters returned from useSupercluster will be based on previous data despite zoom/bounds/points having changed. For example, using isFetching from useQuery, we can set disableRefresh so that Supercluster doesn't perform clustering until we've successfully fetched new data.

const Component = () => {
  const { data, isFetching } = useQuery("markers", getMarkers());

  const { clusters, supercluster } = useSupercluster({
    /* ... normal options passed to hook ... */
    disableRefresh: isFetching

  return (
      { => {
        return <Marker />;

Package Sidebar


npm i use-supercluster

Weekly Downloads






Unpacked Size

11.3 kB

Total Files


Last publish


  • leighhalliday