Hooks System
React HERE Maps is built using a modern hook-based architecture that provides clean, composable functionality.Core Hooks
useMapContext
Access the map context from any child component:useCreateMap
Internal hook used byHereMap to initialize the map instance. Not typically used directly, but understanding it helps with advanced customization.
useMapResize
Automatically handles map resize events. Used internally byHereMap:
Component-Specific Hooks
useMarker
Powers theMarker component. Creates and manages markers:
useMarkerDragBehavior
Handles marker drag functionality:usePolyline
Creates and manages polylines:usePolygon
Creates and manages polygons:Custom Hook Patterns
Creating a Map Bounds Hook
Geolocation Hook
Map Events Hook
Distance Measurement Hook
Hook Best Practices
Composition over inheritance
Composition over inheritance
Build complex functionality by composing simple hooks:
Memoization
Memoization
Use
useMemo and useCallback for expensive computations:Cleanup
Cleanup
Always clean up side effects:
Type safety
Type safety
Define proper TypeScript types for custom hooks: