Last active
May 13, 2020 18:18
-
-
Save SpangleLabs/d89a2f947b9c3b3c4ddafaebfca1df6b to your computer and use it in GitHub Desktop.
InfoWindow in Marker map test for @react-google-maps/api PR
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script src="MapTest.tsx"></script> | |
</head> | |
<body> | |
<div id="main"> | |
</div> | |
</body> | |
</html> |
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 * as ReactDOM from "react-dom"; | |
import * as React from "react"; | |
import {GoogleMap, InfoWindow, LoadScript, Marker} from "@react-google-maps/api"; | |
//import LoadScript from "../../../react-google-maps-api/packages/react-google-maps-api/src/LoadScript"; | |
//import GoogleMap from "../../../react-google-maps-api/packages/react-google-maps-api/src/GoogleMap" | |
//import InfoWindow from "../../../react-google-maps-api/packages/react-google-maps-api/src/components/drawing/InfoWindow" | |
//import Marker from "../../../react-google-maps-api/packages/react-google-maps-api/src/components/drawing/Marker" | |
import config from "./config"; | |
export const MapTest: React.FunctionComponent = () => { | |
const mapCentre = {lat: 55, lng: -3} | |
const mapStyle = { | |
height: "800px", | |
width: "800px" | |
} | |
const markerPosition = {lat: 57, lng: -3} | |
return <LoadScript googleMapsApiKey={config['google_maps_key']}> | |
<GoogleMap | |
zoom={6} | |
center={mapCentre} | |
id="map" | |
mapContainerStyle={mapStyle} | |
> | |
<Marker position={markerPosition}> | |
<InfoWindow> | |
<div>Hello</div> | |
</InfoWindow> | |
</Marker> | |
</GoogleMap> | |
</LoadScript> | |
} | |
document.addEventListener("DOMContentLoaded", function () { | |
ReactDOM.render(<MapTest/>, document.getElementById("main")); | |
}); |
Oh, interesting! I didn't know about that. Do you know anywhere I can read a bit more on it?
Should that be outside the component (which feels it breaks encapsulation a bit), or just higher in it?
I've edited now, to pull those objects out higher into the component. I can easily pull those out the function if you want.
But it should demonstrate that the PR works at least
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please do not pass new objects as props! it messes up with re-renders and performance. You need to cache center, mapContainerStyle and position props before passing it to components