Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/googlemaps/react-wrapper
Wrap React components with this libary to load the Google Maps JavaScript API.
https://github.com/googlemaps/react-wrapper
google-maps language-extension react
Last synced: 2 months ago
JSON representation
Wrap React components with this libary to load the Google Maps JavaScript API.
- Host: GitHub
- URL: https://github.com/googlemaps/react-wrapper
- Owner: googlemaps
- License: apache-2.0
- Created: 2021-03-01T21:30:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T05:03:00.000Z (10 months ago)
- Last Synced: 2024-04-08T06:22:40.275Z (10 months ago)
- Topics: google-maps, language-extension, react
- Language: TypeScript
- Homepage:
- Size: 3.86 MB
- Stars: 350
- Watchers: 12
- Forks: 49
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Google Maps JavaScript API React Wrapper
[![npm](https://img.shields.io/npm/v/@googlemaps/react-wrapper)](https://www.npmjs.com/package/@googlemaps/react-wrapper)
![Build](https://github.com/googlemaps/react-wrapper/workflows/Test/badge.svg)
![Release](https://github.com/googlemaps/react-wrapper/workflows/Release/badge.svg)
[![codecov](https://codecov.io/gh/googlemaps/react-wrapper/branch/master/graph/badge.svg)](https://codecov.io/gh/googlemaps/react-wrapper)
![GitHub contributors](https://img.shields.io/github/contributors/googlemaps/react-wrapper?color=green)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![](https://github.com/jpoehnelt/in-solidarity-bot/raw/main/static//badge-flat-square.png)](https://github.com/apps/in-solidarity)> [!NOTE]
> Development of this package has been discontinued.
> We recommend all users of this package to switch to the new
> [`@vis.gl/react-google-maps`](https://www.npmjs.com/package/@vis.gl/react-google-maps),
> which provides a collection of components and hooks and can be configured
> to be fully compatible with this package.
>
> See [the migration guide](https://visgl.github.io/react-google-maps/docs/guides/migrating-from-react-wrapper)
> for more details on how to switch from this package to `@vis.gl/react-google-maps`.## Description
Wrap React components with this library to load the Google Maps JavaScript API.
```jsx
import {Wrapper} from '@googlemaps/react-wrapper';const MyApp = () => (
);
```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.
```jsx
import {Wrapper, Status} from '@googlemaps/react-wrapper';const render = status => {
switch (status) {
case Status.LOADING:
return ;
case Status.FAILURE:
return ;
case Status.SUCCESS:
return ;
}
};const MyApp = () => ;
```When combining children and render props, the children will render on success and the render prop will be executed for other status values.
```tsx
import {Wrapper, Status} from '@googlemaps/react-wrapper';const render = (status: Status): ReactElement => {
if (status === Status.FAILURE) return ;
return ;
};const MyApp = () => (
);
```### @googlemaps/js-api-loader
This wrapper uses [@googlemaps/js-api-loader][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][js_api_loader] are also accepted as props to the wrapper component.
### MyMapComponent
The following snippets demonstrates the usage of `useRef` and `useEffect` hooks with Google Maps.
```tsx
function MyMapComponent({
center,
zoom,
}: {
center: google.maps.LatLngLiteral;
zoom: number;
}) {
const ref = useRef();useEffect(() => {
new window.google.maps.Map(ref.current, {
center,
zoom,
});
});return
;
}
```## Examples
See the [examples](https://github.com/googlemaps/react-wrapper/tree/main/examples) folder for additional usage patterns.
- [Basic Demo](https://googlemaps.github.io/react-wrapper/public/basic/)
## Install
Available via npm as the package [@googlemaps/react-wrapper](https://www.npmjs.com/package/@googlemaps/react-wrapper).
```sh
npm i @googlemaps/react-wrapper
```or
```sh
yarn add @googlemaps/react-wrapper
```For TypeScript support additionally install type definitions.
```sh
npm i -D @types/google.maps
```or
```sh
yarn add -D @types/google.maps
```## Documentation
The reference documentation can be found at this [link](https://googlemaps.github.io/react-wrapper/index.html).
## Support
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][issues]. If you'd like to
contribute, please read [How to Contribute][contrib].[issues]: https://github.com/googlemaps/react-wrapper/issues
[contrib]: https://github.com/googlemaps/react-wrapper/blob/master/CONTRIBUTING.md
[js_api_loader]: https://www.npmjs.com/package/@googlemaps/js-api-loader