In the following code for example, how can I update react-query to wait for the previous call to be complete before starting the next one?
I'm trying to hit an API that has rate limiting to one call at a time but I have a list of calls I need to make, I get a 429 if more than one are done at the same time.
const [selection, setSelection] = React.useState([])
const results = useQueries(
selection.map(item => ({
queryKey: ['something', item]
queryFn: () => fetchItem(item)
})
)
const data = results.map(result => result.data)
I'm not aware of a built-in solution.
But how about this. A state that counts queries that have been run, and enables the next query.
You might need
staleTime: Infinity
to make sure the library doesn't refetch all queries at the same time.