As far as I know, the data obtained by calling the API with useQuery is turned into a map to spray it on the screen.
export const getList = async () => {
const { data } = await api.get("/~/~/~/list");
return data;
};
export const getNewList = async () => {
const { data } = await api.get("/~/~/~/new-list");
return data;
};
If there are these two things to bring, how should I use useQuery?
react
The useQuery does not import only one api.
It's convenient to think of it as a function to get the result of executing an asynchronous function into a hook.
const {
data, // returned to array by code below. If it fails, it is undefined.
} } = useQuery(
['getList', 'getNewList'],
async () => {
// The logic inside this function can be written as desired.
const list = await getList();
const newList = await getNewList();
// You can also do the return method as you wish.
return [list, newList];
},
);
Make a habit of reading official documents!
© 2024 OneMinuteCode. All rights reserved.