简体   繁体   English

TypeError:解构不可迭代实例的无效尝试。 为了可迭代,非数组对象必须有一个 [Symbol.iterator]() 方法

[英]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我正在尝试从 function 触发一个 rtk 查询端点

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. api 工作正常,我通过硬编码纬度和经度值交叉检查并获得成功响应。

response from api来自 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无效的解构不可迭代实例的尝试。 为了可迭代,非数组对象必须有一个 [Symbol.iterator]() - TypeError: Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() 对不可迭代实例的解构尝试无效。 为了可迭代,非数组对象必须有一个 [Symbol.iterator]() 方法 - Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method 获取错误为“传播不可迭代实例的尝试无效。 为了可迭代,非数组对象必须有一个 [Symbol.iterator]() 方法' - Getting error as 'Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method' React js:传播不可迭代实例的无效尝试。 为了可迭代,非数组对象必须有一个 [Symbol.iterator]() 方法 - React js : Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method 未处理的拒绝(TypeError):破坏非迭代实例的无效尝试 - Unhandled Rejection (TypeError): Invalid attempt to destructure non-iterable instance 解构不可迭代实例的无效尝试 - Invalid attempt to destructure non-iterable instance 未捕获的 TypeError:无效的解构不可迭代实例的尝试 - Uncaught TypeError: Invalid attempt to destructure non-iterable instance TypeError:对不可迭代实例 React/Jest 的解构尝试无效 - TypeError: Invalid attempt to destructure non-iterable instance React/Jest 将项目添加到 Reducer 中的空数组中会给出错误“类型错误:传播不可迭代实例的尝试无效”。 - Add Items into Empty array in Reducer give Error 'TypeError: Invalid attempt to spread non-iterable instance.' 解构不可迭代实例的无效尝试 - React Native - Invalid attempt to destructure non-iterable instance - React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM