Gathering detailed insights and metrics for @googlemaps/react-wrapper
Gathering detailed insights and metrics for @googlemaps/react-wrapper
Gathering detailed insights and metrics for @googlemaps/react-wrapper
Gathering detailed insights and metrics for @googlemaps/react-wrapper
Wrap React components with this libary to load the Google Maps JavaScript API.
npm install @googlemaps/react-wrapper
Typescript
Module System
Node Version
NPM Version
94.9
Supply Chain
100
Quality
80.8
Maintenance
100
Vulnerability
100
License
TypeScript (55.81%)
JavaScript (44.19%)
Total Downloads
17,548,413
Last Day
4,595
Last Week
83,098
Last Month
534,129
Last Year
7,260,793
374 Stars
794 Commits
54 Forks
14 Watching
10 Branches
18 Contributors
Latest Version
1.1.42
Package Id
@googlemaps/react-wrapper@1.1.42
Unpacked Size
34.21 kB
Size
9.03 kB
File Count
11
NPM Version
10.8.1
Node Version
20.16.0
Publised On
09 Aug 2024
Cumulative downloads
Total Downloads
Last day
-83.1%
4,595
Compared to previous day
Last week
-39.3%
83,098
Compared to previous week
Last month
-9.4%
534,129
Compared to previous month
Last year
1.1%
7,260,793
Compared to previous year
1
1
27
Wrap React components with this library to load the Google Maps JavaScript API.
1import { Wrapper } from "@googlemaps/react-wrapper"; 2 3const MyApp = () => ( 4 <Wrapper apiKey={"YOUR_API_KEY"}> 5 <MyMapComponent /> 6 </Wrapper> 7);
The preceding example will not render any elements unless the Google Maps JavaScript API is successfully loaded. To handle error cases and the time until load is complete, it is recommended to provide render props.
1import { Wrapper, Status } from "@googlemaps/react-wrapper"; 2 3const render = (status) => { 4 switch (status) { 5 case Status.LOADING: 6 return <Spinner />; 7 case Status.FAILURE: 8 return <ErrorComponent />; 9 case Status.SUCCESS: 10 return <MyMapComponent />; 11 } 12}; 13 14const MyApp = () => <Wrapper apiKey={"YOUR_API_KEY"} render={render} />;
When combining children and render props, the children will render on success and the render prop will be executed for other status values.
1import { Wrapper, Status } from "@googlemaps/react-wrapper"; 2 3const render = (status: Status): ReactElement => { 4 if (status === Status.FAILURE) return <ErrorComponent />; 5 return <Spinner />; 6}; 7 8const MyApp = () => ( 9 <Wrapper apiKey={"YOUR_API_KEY"} render={render}> 10 <MyMapComponent /> 11 </Wrapper> 12);
This wrapper uses @googlemaps/js-api-loader to load the Google Maps JavaScript API. This library uses a singleton pattern and will not attempt to load the library more than once. All options accepted by @googlemaps/js-api-loader are also accepted as props to the wrapper component.
The following snippets demonstrates the usage of useRef
and useEffect
hooks with Google Maps.
1function MyMapComponent({
2 center,
3 zoom,
4}: {
5 center: google.maps.LatLngLiteral;
6 zoom: number;
7}) {
8 const ref = useRef();
9
10 useEffect(() => {
11 new window.google.maps.Map(ref.current, {
12 center,
13 zoom,
14 });
15 });
16
17 return <div ref={ref} id="map" />;
18}
See the examples folder for additional usage patterns.
Available via npm as the package @googlemaps/react-wrapper.
1npm i @googlemaps/react-wrapper
or
1yarn add @googlemaps/react-wrapper
For TypeScript support additionally install type definitions.
1npm i -D @types/google.maps
or
1yarn add -D @types/google.maps
The reference documentation can be found at this link.
This library is community supported. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it.
If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
Found 3/4 approved changesets -- score normalized to 7
Reason
3 existing vulnerabilities detected
Details
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-12-23
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