[英]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.