Gathering detailed insights and metrics for @react-google-maps/api
Gathering detailed insights and metrics for @react-google-maps/api
Gathering detailed insights and metrics for @react-google-maps/api
Gathering detailed insights and metrics for @react-google-maps/api
@react-google-maps/infobox
InfoBox for React.js Google Maps API
@react-google-maps/marker-clusterer
Marker Clusterer for React.js Google Maps API
@vis.gl/react-google-maps
React components and hooks for the Google Maps JavaScript API
@googlemaps/react-wrapper
React component that wraps the loading of Google Maps JavaScript API.
npm install @react-google-maps/api
Typescript
Module System
Node Version
NPM Version
91.1
Supply Chain
94.8
Quality
81.7
Maintenance
100
Vulnerability
99.3
License
TypeScript (95.96%)
JavaScript (3.76%)
CSS (0.28%)
Total Downloads
67,054,584
Last Day
129,679
Last Week
656,198
Last Month
2,757,054
Last Year
27,571,557
1,833 Stars
1,982 Commits
446 Forks
23 Watching
99 Branches
94 Contributors
Minified
Minified + Gzipped
Latest Version
2.20.3
Package Id
@react-google-maps/api@2.20.3
Unpacked Size
5.73 MB
Size
1.06 MB
File Count
147
NPM Version
10.8.3
Node Version
22.9.0
Publised On
11 Oct 2024
Cumulative downloads
Total Downloads
Last day
-1%
129,679
Compared to previous day
Last week
8.8%
656,198
Compared to previous week
Last month
3.3%
2,757,054
Compared to previous month
Last year
42.4%
27,571,557
Compared to previous year
6
33
@react-google-maps/api
You can donate or became a sponsor of the project here: https://opencollective.com/react-google-maps-api#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 Versions starting 12.20.0 should support React@19.
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/api 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 PNPM
1pnpm install @react-google-maps/api
with NPM
1npm i -S @react-google-maps/api
1import React from 'react' 2import { GoogleMap, useJsApiLoader } from '@react-google-maps/api' 3 4const containerStyle = { 5 width: '400px', 6 height: '400px', 7} 8 9const center = { 10 lat: -3.745, 11 lng: -38.523, 12} 13 14function MyComponent() { 15 const { isLoaded } = useJsApiLoader({ 16 id: 'google-map-script', 17 googleMapsApiKey: 'YOUR_API_KEY', 18 }) 19 20 const [map, setMap] = React.useState(null) 21 22 const onLoad = React.useCallback(function callback(map) { 23 // This is just an example of getting and using the map instance!!! don't just blindly copy! 24 const bounds = new window.google.maps.LatLngBounds(center) 25 map.fitBounds(bounds) 26 27 setMap(map) 28 }, []) 29 30 const onUnmount = React.useCallback(function callback(map) { 31 setMap(null) 32 }, []) 33 34 return isLoaded ? ( 35 <GoogleMap 36 mapContainerStyle={containerStyle} 37 center={center} 38 zoom={10} 39 onLoad={onLoad} 40 onUnmount={onUnmount} 41 > 42 {/* Child components, such as markers, info windows, etc. */} 43 <></> 44 </GoogleMap> 45 ) : ( 46 <></> 47 ) 48} 49 50export 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:
1// before - don't do this! 2<GoogleMap 3 ref={(map) => { 4 const bounds = new window.google.maps.LatLngBounds() 5 6 map.fitBounds(bounds) 7 }} 8/>
After:
1<GoogleMap 2 onLoad={(map) => { 3 const bounds = new window.google.maps.LatLngBounds() 4 map.fitBounds(bounds) 5 }} 6 onUnmount={(map) => { 7 // do your stuff before map is unmounted 8 }} 9/>
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/api<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 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-api/package.json
change main
to "src/index.ts"
module
fieldreact-google-maps-api-gatsby-example
to test your changes. Just make sure you change the import from @react-google-maps/api
to ../../../react-google-maps-api
Since 1.2.0 you can use onLoad and onMount props for each @react-google-maps/api 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.
No vulnerabilities found.
Reason
8 commit(s) and 8 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/14 approved changesets -- score normalized to 7
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
56 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-09
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More