Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
react-google-maps-pro
Advanced tools
@react-google-maps-pro
You can donate or became a sponsor of the project here: https://opencollective.com/@react-google-maps-pro#category-CONTRIBUTE
This library requires React v16.6 or later. To use the latest features (including hooks) requires React v16.8+. If you need support for earlier versions of React, you should check out react-google-maps
This is complete re-write of the (sadly unmaintained) react-google-maps
library. We thank tomchentw for his great work that made possible.
@react-google-maps-pro provides very simple bindings to the google maps api and lets you use it in your app as React components.
Here are the main additions to react-google-maps that were the motivation behind this re-write
with NPM
npm i -S @react-google-maps-pro
or Yarn
yarn add @react-google-maps-pro
import React from 'react'
import { GoogleMap, useJsApiLoader } from '@react-google-maps-pro';
const containerStyle = {
width: '400px',
height: '400px'
};
const center = {
lat: -3.745,
lng: -38.523
};
function MyComponent() {
const { isLoaded } = useJsApiLoader({
id: 'google-map-script',
googleMapsApiKey: "YOUR_API_KEY" //Get an API Key from https://gomaps.pro free trial available
})
const [map, setMap] = React.useState(null)
const onLoad = React.useCallback(function callback(map) {
// This is just an example of getting and using the map instance!!! don't just blindly copy!
const bounds = new window.google.maps.LatLngBounds(center);
map.fitBounds(bounds);
setMap(map)
}, [])
const onUnmount = React.useCallback(function callback(map) {
setMap(null)
}, [])
return isLoaded ? (
<GoogleMap
mapContainerStyle={containerStyle}
center={center}
zoom={10}
onLoad={onLoad}
onUnmount={onUnmount}
>
{ /* Child components, such as markers, info windows, etc. */ }
<></>
</GoogleMap>
) : <></>
}
export default React.memo(MyComponent)
if you need an access to map object, instead of ref
prop, you need to use onLoad
callback on <GoogleMap />
component.
Before:
// before - don't do this!
<GoogleMap
ref={map => {
const bounds = new window.google.maps.LatLngBounds();
map.fitBounds(bounds);
}}
/>
After:
<GoogleMap
onLoad={map => {
const bounds = new window.google.maps.LatLngBounds();
map.fitBounds(bounds);
}}
onUnmount={map => {
// do your stuff before map is unmounted
}}
/>
If you want to use window.google
object, you need to extract GoogleMap in separate module, so it is lazy executed then google-maps-api
script is loaded and executed by <LoadScript />
. If you try to use window.google
before it is loaded it will be undefined and you'll get a TypeError.
12.4kb
gzip, tree-shakeable https://bundlephobia.com/result?p=@react-google-maps-pro<LoadScript preventGoogleFonts />
componentExamples can be found in two places:
Using the examples requires you to generate a google maps api key. For instructions on how to do that please see the following guide
You can join the community at Spectrum.chat to ask questions and help others with your experience or join our Slack channel
Maintainers and contributors are very welcome! See this issue to get started.
When working on a feature/fix, you're probably gonna want to test your changes. This workflow is a work in progress. Please feel free to improve it!
packages/@react-google-maps-pro/package.json
change main
to "src/index.ts"
module
field@react-google-maps-pro-gatsby-example
to test your changes. Just make sure you change the import from @react-google-maps-pro
to ../../../@react-google-maps-pro
Since 1.2.0 you can use onLoad and onMount props for each @react-google-maps-pro component, ref does not contain API methods anymore.
Since version 1.2.2 We added useGoogleMap hook, which is working only with React@16.8.1 and later versions.
nycmesh.net Network topography visualized on the map (Github)
add your website by making PR!
FAQs
@react-google-maps-pro API integration
The npm package react-google-maps-pro receives a total of 0 weekly downloads. As such, react-google-maps-pro popularity was classified as not popular.
We found that react-google-maps-pro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.