Skip to content

perf: memoize components to prevent unnecessary re-renders#59

Merged
lodev09 merged 4 commits intomainfrom
perf/memoize-components
Mar 26, 2026
Merged

perf: memoize components to prevent unnecessary re-renders#59
lodev09 merged 4 commits intomainfrom
perf/memoize-components

Conversation

@lodev09
Copy link
Copy Markdown
Collaborator

@lodev09 lodev09 commented Mar 26, 2026

Summary

Memoize all map components (web + native) to prevent unnecessary re-renders during marker drag and camera events. Previously, setStatus calls in the example app triggered full re-render cascades through MapView and all child components, causing visible lag during marker drag operations.

  • Add memo/PureComponent to MapView, Marker, Polygon, Circle, GroundOverlay, Polyline, TileOverlay, GeoJson
  • Stabilize MapView.web event handlers with useCallback and memoize context value
  • Replace isDragging state with ref to avoid mid-drag re-renders that reset camera position
  • Extract inline callbacks in example app to stable useCallback refs

Type of Change

  • Bug fix

Test Plan

  • Drag markers on web — no lag, status updates in real-time
  • Drag map on web — camera no longer resets to previous position
  • Polyline animation pauses during map drag, resumes after
  • Marker callouts, press events, and overlays work as before

Checklist

  • I tested on iOS
  • I tested on Android
  • I tested on Web
  • I updated the documentation (if needed)

lodev09 added 4 commits March 26, 2026 18:38
- Add memo/PureComponent to MapView, Marker, Polygon, Circle,
  GroundOverlay, Polyline, TileOverlay, GeoJson (web + native)
- Stabilize MapView.web handlers with useCallback and isDraggingRef
- Memoize MapContext value to avoid consumer re-renders
- Extract inline callbacks in example Home to stable useCallback refs
- Wrap example Map with memo(forwardRef)
- Use PureComponent for native MapView
- Add memo to web components: MapView, Marker, Polygon, Circle,
  GroundOverlay, Polyline, TileOverlay, GeoJson
- Stabilize MapView.web handlers with useCallback and isDraggingRef
- Memoize MapContext value to avoid consumer re-renders
- Extract inline callbacks in example Home to stable useCallback refs
- Wrap example Map with memo(forwardRef)
…uring drag

State updates from setIsDragging caused MapView re-renders mid-drag,
resetting the camera position. Using a ref avoids re-renders while
still pausing Polyline animation during drag.
@lodev09 lodev09 merged commit ad5d3d4 into main Mar 26, 2026
3 checks passed
@lodev09 lodev09 deleted the perf/memoize-components branch March 26, 2026 11:43
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.

1 participant