JustFly1984 / react-google-maps-api

React Google Maps API
MIT License
1.79k stars 438 forks source link

Loading google maps JS API #3334

Open TimWalkidenWebPro opened 7 months ago

TimWalkidenWebPro commented 7 months ago

The following warning has started to appear when using the following @react-google-maps/api/src/LoadScriptNext.

Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance. For best-practice loading patterns please see https://goo.gle/js-api-loading

Is their a fix for this?

keita-makino commented 7 months ago

Wow, I've been just looking for this feature :O

rhadooqoo commented 7 months ago

You must update to the latest version and replace useLoadScript with the newer useJsApiLoader

import { useJsApiLoader } from "@react-google-maps/api";

sderrow commented 7 months ago

@rhadooqoo I'm not sure that solves the problem because this library is still using v1.16.2 of @googlemaps/js-api-loader, but that library only fixed loading=async as of v1.16.3 here.

christopherboisvert commented 6 months ago

@sderrow Updated to latest version and it worked for me. Thanks @nitya-nalamari 👍

christopherboisvert commented 6 months ago

This issue should be closed since it is resolved.

Vitallyz commented 6 months ago

Did not work for me (updated to 2.19.3). For now, injecting with the API key till the library is updated.

googleMapsApiKey: `${import.meta.env.VITE_GOOGLE_MAP_KEY}&loading=async`,
nitya-nalamari commented 6 months ago

@Vitallyz loading=async was added for the LoadScript component in my PR. My PR was merged only a few days ago so not sure if it has been released yet.

The fix you mentioned is what I am currently using as well 😅