Skip to content

Instantly share code, notes, and snippets.

@everdimension
Created August 31, 2022 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everdimension/7cc3fc1c90978a9176245bb825f90356 to your computer and use it in GitHub Desktop.
Save everdimension/7cc3fc1c90978a9176245bb825f90356 to your computer and use it in GitHub Desktop.
// just a reminder of a nice API for a <Script /> component,
// reference: https://nextjs.org/docs/basic-features/script#executing-code-after-mounting-onready
import { useRef } from 'react'
import Script from 'next/script'
export function Home() {
const mapRef = useRef()
return (
<>
<div ref={mapRef}></div>
<Script
id="google-maps"
src="https://maps.googleapis.com/maps/api/js"
onReady={() => {
new google.maps.Map(mapRef.current, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
})
}}
/>
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment