Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memoize context-values to avoid excessive re-renders #287

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

usefulthink
Copy link
Collaborator

Add memoization to all context values used internally. Without the memoization, the context value of e.g. the GoogleMapsContext (used to retrieve the map-instance in the useMap hook) will register as changed every time the map-component re-renders, causing all children that use the context (for example via the useMap hook) to re-render as well. With the memoization in place, these unnecessary renders will no longer happen.

fixes #285

@usefulthink usefulthink force-pushed the fix/memoize-context-values branch 2 times, most recently from ea51a9b to a849cf5 Compare March 29, 2024 14:45
Add memoization to all context values used internally.
Without the memoization, the context value of e.g. the GoogleMapsContext (used to retrieve the map-instance in the `useMap` hook) will register as changed every time the map-component re-renders, causing all children that use the context (for example via the `useMap` hook) to re-render as well.
With the memoization in place, these unnecessary renders will no longer happen.

fixes visgl#285
@usefulthink usefulthink force-pushed the fix/memoize-context-values branch from a849cf5 to f77f532 Compare March 29, 2024 15:06
@usefulthink usefulthink merged commit bea68f9 into visgl:main Mar 29, 2024
2 checks passed
@usefulthink usefulthink deleted the fix/memoize-context-values branch March 29, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] any component using the useMap hook gets rerendered anytime the map is panned/zoomed
1 participant