简体   繁体   中英

TypeError: Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method

I am trying to trigger a rtk query end point from a function

const [getcitycode, { isLoading, error, data, isSuccess, isError }] = useLocationQuery();

const getLocationDetails = async () => {
  const queryItems = { latitude: lat, longitude: long };
  await getcitycode(queryItems);
};

this is the end point

location:builder.query({
  query: (queryItems) => {
    console.log('qitems', queryItems);
    return {
      url: `https://revgeocode.search.hereapi.com/v1/revgeocode?
        at=${queryItems.latitude},${queryItems.longitude}&lang=en-
       US&apiKey=apikey`,
      method: 'GET',
    };
  },
});

the api is working fine, i cross checked by hard coding latitude and longitude value and getting successful response.

response from api

{
  "currentData": {
    "items": [[Object]]
  },
  "data": {
    "items": [[Object]]
  },
  "endpointName": "location",
  "fulfilledTimeStamp": 1675000730551,
  "isError": false,
  "isFetching": false,
  "isLoading": false,
  "isSuccess": true,
  "isUninitialized": false,
  "refetch": [Function refetch],
  "requestId": "uKRzgDyIYxgdDc1wAcScf",
  "startedTimeStamp": 1675000730127,
  "status": "fulfilled"
}

Change from (replace square brackets with curly brackets):

const [getcitycode, { isLoading, error, data, isSuccess, isError }] = useLocationQuery();
const {getcitycode, { isLoading, error, data, isSuccess, isError }} = useLocationQuery();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM