useSuperCluster hook returns empty array when data was passed in props.
vitaly-scentroid opened this issue · comments
I can replicate the example from video tutorial, but when I request data with fetch from parent component and pass it as a prop to my map(child) component to create clusters, clusters array always end up being empty. It's the same thing, but basically without useSwr. Is useSwr a requirement to run use-supercluster? If not, how would you do it?
That's the way I tried to implement it
const nodes = props.flight?.samples ? props.flight.samples : [];
const heatPositions = nodes.map( node => ({
lat: node.latitude,
lng: node.longitude,
weight: 2
}));
console.log('nodes: ', nodes);
const points = nodes.map( node => ({
type: 'Feature',
properties: {
cluster: false,
nodeId: node.timestamp,
value: node.values
},
geometry: { type: 'Point', coordinates: [node.longitude, node.latitude] }
}));
console.log('points: ', points);
// 4. use-cluster
const { clusters, supercluster } = useSupercluster({
points,
bounds,
zoom,
options: { radius: 75, maxZoom: 20 }
})
console.log('clusters:', clusters);
@vitaly-scentroid I just bumped dequal from v1 to v2, hoping that this is the cause and something has been fixed. If it does not fix things, please produce a minimal reproducible repo that I can clone and try out... or feel free to jump in and check things out. This package is literally under 50 lines long in a single file :D https://github.com/leighhalliday/use-supercluster/blob/master/src/index.tsx
Yeah that fixed it! Thanks for quick response