From Imperative to Declarative: Simplifying JavaScript APIs with React.js
summary
Shows how to wrap the Google Maps JavaScript API in a declarative React component using the Google Maps loader and the Maps and Marker constructors, a custom useMap hook that returns a container ref and map ref, and small hooks (useCenter, useZoom, useIdle) that run imperative updates inside useEffect. Uses context to let child Marker components new up markers, keeps the map in a ref to avoid rerenders, and lets external state control center/zoom while encapsulating imperative logic.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 1:09Imperative vs declarative
- 3:16Code examples comparison
- 5:45Benefits of declarative code
- 7:56Simplifying JavaScript APIs
- 10:04Declarative Google Maps API
- 13:58Handling map center prop
- 15:44Adding zoom and idle hooks
- 16:24Adding markers with context
- 18:53Conclusion and benefits
related talks
50mBuilding with Mapbox GL JS in React
36mDeclarative APIs in an Imperative World
22mIntegrating React.js and Shiny
15mFrom Imperative to Declarative
27mMixed Mode React
59mDeveloping React Applications with Functional Components
23mHow to Roll Your React Components Like a Good Inside-Out Sushi
27mEric Bishard - State Management with React Hooks
