1

I was following a tutorial on how to add google maps to a react/expo javascript project. I am new to the javascript language and have had a bug that I cannot find an answer to. when compiling the app I am given the error "TypeError: Object(...) is not a function". here is the link to the tutorial: https://www.youtube.com/watch?v=WZcxJGmLbSo&t. Thank you.

The error is on the line 25 of the script:

22 | 
  23 | 
  24 | }
> 25 | export default function App() {
  26 |   const {isLoaded, LoadError} = UseLoadScript({
  27 |     googleMapsApiKey: process.env.REACT_APP_GOOGLE_MAPS_API_KEY,
  28 |     libraries,```

Full script:

import React from 'react';

import {
  GoogleMap,
  UseLoadScript,
  Marker,
  InfoWindow,

} from "@react-google-maps/api";

const libraries = ["places"];
const mapContainerStyle = {
  width: "100vw",
  height: "100vh",

};

const center = {
  lat: 43.653225,
  lng: -79.383186


}
export default function App() {
  const {isLoaded, LoadError} = UseLoadScript({
    googleMapsApiKey: process.env.REACT_APP_GOOGLE_MAPS_API_KEY,
    libraries,
  });
   
  
  if (LoadError) return "Error Loading maps";
  if (!isLoaded) return "Loading Maps";

  return <div> 

    <GoogleMap> 
      mapContainerStyle={mapContainerStyle} 
      zoom={8}
      center={center}
      </GoogleMap>
  </div>
  
}

2 Answers 2

1

I think your import(UseLoadScript) is wrong. Check here once useLoadScript

import { useLoadScript } from '@react-google-maps/api';
Sign up to request clarification or add additional context in comments.

Comments

0

I solve similar problem by upgrading React to v16.8+ to support the usage of hooks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.