YA Google Maps React Library

YA Google Maps React Library

YA Google Maps React Library . A lightweight React hook-based library for a simple Google Maps API usage

YA Google Maps React Library

A lightweight React hook-based library for a simple Google Maps API usage

As this article explains well, there is no official React library from Google for Google Maps, but there is a JS API Google Maps.

Adopting a library that allows using components like <Map /> and its children <Pinpoint /> <Circle /> etc... helps us by the point of view of code readability, but with some drawbacks:

  • You won't have full control of the API, or if you need it you'll probably find yourself into several workarounds;
  • You heavily rely on the library;
  • You add overhead;
  • You can't use community help efficiently.

So, the goal of this library is helping us to load the API via a hook_ and have the _full control of Google Maps API, even when we use JSX components for an easier development.

This library does exactly that job: it loads google Maps API asynchronously, and it returns the google object. Period.


First, install the library:

npm install --save ya-google-maps-react

Automatically Lazy-loading Google API

The library includes a helper Hook that returns the Google maps API.

The useGoogleApi hook accepts:

  • key: you must define it;
  • libraries: an array of libraries that you need to load. It defaults to places.

See src/index.dev.js for a full example:

import useGoogleAPI from './index';

// ...

const MyComponent = (): React.Node => {
  const googleApi = useGoogleAPI('MY-API-KEY-HERE');
  const mapRef = React.useRef(null);  

  // ...

  React.useEffect(() => {
    if (googleApi === null) return;

    new googleApi.maps.Map(mapRef.current, {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8,
  }, [googleApi]);

  // ...

Future evolution

  • bad case scenarios tests
  • Some complementary components, in order to allow a fast development for simple cases, but with full control on the object.


If you have some issues, please make an issue on the issues tab and try to include an example.


git clone https://github.com/bertuz/ya-google-maps-react.git
cd ya-google-maps-react
npm install
make watch

Download Details:

Author: bertuz

Source Code: https://github.com/bertuz/ya-google-maps-react

react reactjs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Increase Performance of React Applications Via Array JavaScript Methods

Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.

Routing in React without React-Router

I have been using React JS in my projects for quite some time now and am used to managing routing in my app using the react-router package. I have always been keen on having as little dependencies in my apps as possible, so, I always felt perturbed by the use of this particular package in simpler apps which did not have complex routes.

The Ugly Side of React Hooks

In this post, I will share my own point of view about React Hooks, and as the title of this post implies, I am not a big fan.

Forms of Composition in JavaScript and React

One of the core ideas in functional programming is composition: building larger things from smaller things. The canonical example of this idea should be familiar with legos.