I'm looking to fetch pages from wikipedia API. for the sake of keeping this short I won't explain in deep, but the bottom line is that i need to use what returned in previous request (when resolved) as params in a new one.
"batchcomplete": "",
"continue": {
"grncontinue": "0.117298963004|0.117302224597|46297018|0",
"continue": "grncontinue||"
I've tried sevral appraoches, here's my latest try:
const results = useQueries([
{
queryKey: [`getRandomWikis-${count}`],
queryFn: async () => {
const res = await axios.get(url + endpoint);
setEndpoint(`&grncontinue||=${res.data?.data?.continue?.grncontinue}`);
setCount((prev) => prev + 1);
setAllData((prev) => [...prev, res.data?.data?.query?.pages]);
return res;
},
enabled: isLocalStorageEmpty,
},
{
queryKey: [`getRandomWikis-${count}`],
queryFn: async () => {
const res = await axios.get(url + endpoint);
setEndpoint(`&grncontinue||=${res.data?.data?.continue?.grncontinue}`);
setCount((prev) => prev + 1);
setAllData((prev) => [...prev, res.data?.data.query.pages]);
return res;
},
enabled: isLocalStorageEmpty && count > 1,
},
{
queryKey: [`getRandomWikis-${count}`],
queryFn: async () => {
const res = await axios.get(url + endpoint);
setEndpoint(`&grncontinue||=${res.data?.data?.continue?.grncontinue}`);
setCount((prev) => prev + 1);
setAllData((prev) => [...prev, res.data?.data.query.pages]);
return res;
},
enabled: isLocalStorageEmpty && count > 2,
},
]);
results[2].data?.data && console.log(allData);
i'm getting endless requeast for some reason, my component rerenders many times until craches, and nothing is logged to console.
Ideas? Am I using useQueries wrong? different approaches? (here I made 3 request but the idea is to be able to make even more)
This can be simplified quite a lot if you do the following:
setAllData()and simply refer to data returned from the hook