Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error from Google when using the library #134

Open
DudiKaplan opened this issue Jan 1, 2023 · 8 comments
Open

Error from Google when using the library #134

DudiKaplan opened this issue Jan 1, 2023 · 8 comments

Comments

@DudiKaplan
Copy link

DudiKaplan commented Jan 1, 2023

Hi , when i use this package i got error on the console

You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors.

It happens to everyone, did you do something wrong?

@DarlonHenrique
Copy link

I have the same error here, idk how to solve it using google maps react hooks, im trying to see the original code in repo causing this error, if i found it, i will tell you

@Tmcerlean
Copy link

Also have the same error too.

@playhard21
Copy link

I am having the same error, what should I need to do?

@ktranish
Copy link

ktranish commented Feb 17, 2023

A temporary fix could be to disabled strict mode - reactStrictMode: false. I also found it useful to change the height unit to vh if the map didn't display properly on the screen

@Facupelli
Copy link

Facupelli commented Mar 17, 2023

Also have the same error.

@Sowed
Copy link

Sowed commented Mar 22, 2023

I am getting this too, in a Nextjs project. The problem might be when the Map Provider is rendered.

@Schlomoh
Copy link
Member

Try Wrapping the map container inside the GoogleMapsProvider, with the react <StrictMode></StrictMode> tag. This does not work with nested StrictMode tags though.

In my case I replaced my index.ts/main.ts code with this to not include the strict mode:

import ReactDOM from "react-dom/client";
import App from "./App.tsx";

ReactDOM.createRoot(document.getElementById("root")!).render(<App />);

Then inside the App:

const App = () => {
  const [mapContainer, setMapContainer] = useState<HTMLDivElement | null>(null);
  const mapRef = useCallback(
    (ref: HTMLDivElement) => ref && setMapContainer(ref),
    []
  );

  const mapsOptions: Partial<GoogleMapsConfiguration["mapOptions"]> = {
    center: { lat: 43.75, lng: 17 },
    zoom: 12,
  };

  return (
      <GoogleMapsProvider
        googleMapsAPIKey={MAPS_API_KEY}
        mapContainer={mapContainer}
        mapOptions={mapsOptions}
      >
        <StrictMode>
          <div ref={mapRef} />
        </StrictMode>
      </GoogleMapsProvider>
  );
};

export default App;

@chwoozy
Copy link

chwoozy commented Nov 20, 2023

Any solution to this @yfr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants