-
-
Save andrerocker/939e66def8bbee0f7a87b1d619fffddb to your computer and use it in GitHub Desktop.
react + google-maps: @googlemaps/react-wrapper (Yes It's really need at least two components)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Wrapper } from "@googlemaps/react-wrapper"; | |
const ParentComponentThatWillReceiveGoogleMap = () => { | |
return <Wrapper apiKey={"42-l337-lol-bbq"}> | |
<MyGoogleMapComponent/> | |
</Wrapper> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyGoogleMapComponent = () => { | |
const ref = useRef(null); | |
const [map, setMap] = useState(); | |
useEffect(() => { | |
if (ref.current && !map) { | |
setMap(new window.google.maps.Map(ref.current, { | |
center: {lat: -23.9851934, lng: -46.2332309}, | |
zoom: 16 | |
}); | |
} | |
}, [map]); | |
return <div style={{height: "800px", width: "100%"}} ref={ref}></div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not production-ready (It's not releasing map-instance properly / useEffect)