user15404864
user15404864

Reputation:

How to map an array of data in reactjs?

I am having trouble on getting the latitude , what i've tried so far is searchLocation.findLocationByAddress.geoCode.latitude and i get this error

error

LocationAdd.js:288 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'latitude')

here is my code

 const { data: searchLocation } = await getLocations({
    variables: {
      placeSearch: {
        address: value
      },
    },
  });
  console.log(searchLocation.findLocationByAddress)
  geoCode = {
    latitude: searchLocation.findLocationByAddress.geoCode.latitude,
    longitude: searchLocation.findLocationByAddress.geoCode.longitude,
  };

enter image description here

Upvotes: 0

Views: 84

Answers (1)

namln-hust
namln-hust

Reputation: 354

findLocationByAddress returns an array, I think you should call .map() or access an element with [].

Upvotes: 1

Related Questions