Maximum update depth exceeded when running the same code as in the InfoWindow example #184
mfmanca2000
started this conversation in
General
Replies: 1 comment 4 replies
-
I'm not sure if you still have this error, but having encountered the same issue, I found a slightly simpler way to manage cluster markers: For example, if
useEffect(() => {
clusterer.current?.clearMarkers();
}, [filteredPoints]);
{filteredPoints.map(point => (
<AdvancedMarker
position={point}
key={point.key}
ref={marker => marker && clusterer.current?.addMarker(marker)}>
<span className="tree">🌳</span>
</AdvancedMarker>
))} I hope this can be useful to someone facing the same issue. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm a victim of the "Maximum update depth exceeded" error when including the code of the Clustering example into my application.
The issue is that in the rendering of the Markers component there's the need to call the setMarkerRef function that in turn calls the setMarkers to change the state of the markers, thing that generates a call to useEffect that will restart the rendering... and I find myself in an infinite loop.
From the example at https://codesandbox.io/p/devbox/github/visgl/react-google-maps/tree/main/examples/marker-clustering in the app.tsx file
The issue doesn't always appear but it happens quite often if I add some filtering to the markers (i.e. a textbox to search through the titles of the markers) and the stack trace is quite clear...
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
at checkForNestedUpdates (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:19655:19)
at scheduleUpdateOnFiber (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:18529:11)
at dispatchSetState (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:13026:15)
at setMarkerRef (http://localhost:5173/src/components/Markers.jsx?t=1706516977171:51:5)
at ref (http://localhost:5173/src/components/Markers.jsx?t=1706516977171:68:28)
at refObject (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:12749:15)
at safelyCallDestroy (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:16737:13)
at commitHookEffectListUnmount (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:16864:19)
at commitMutationEffectsOnFiber (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:17707:21)
at recursivelyTraverseMutationEffects (http://localhost:5173/node_modules/.vite/deps/chunk-UZGXFWLD.js?v=6b3ea6c9:17681:15)
Has anyone else foudn himself in the same situation ?
Beta Was this translation helpful? Give feedback.
All reactions