T
TanStack3y ago
fair-rose

How can i fetch query inside a loop and push back data for each iteration?

Exmaple:
const ids = useQuery({
queryKey: ["ids"],
queryFn: () => fetchIds(),
});

// TODO get a picture for each id and store it in an array
const ids = useQuery({
queryKey: ["ids"],
queryFn: () => fetchIds(),
});

// TODO get a picture for each id and store it in an array
Please help. I will be grateful for your help
2 Replies
fair-rose
fair-roseOP3y ago
help plz
other-emerald
other-emerald3y ago
Maybe fetchQuery or can help you? https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery const data = await queryClient.fetchQuery({ queryKey, queryFn }) Or ParallellQueries https://tanstack.com/query/v4/docs/guides/parallel-queries#dynamic-parallel-queries-with-usequeries Depends on the rest of your code

Did you find this page helpful?