import.meta.env.VITE_GOOGLEMAPS_API_KEY, with no workflow or fetch needed. @googlemaps/js-api-loader and @types/google.maps are pre-installed.
The map component
<MapComponent />.
Markers and geocoding
Gotchas
- Always render the map container, never conditionally. If the
refdiv isn’t in the DOM,mapRef.currentis null and the map never initializes. Overlay loading/error states on top instead. - Give the container an explicit height (e.g.
h-[400px]), or the map renders at zero height.