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.