Skip to content

For useQueries, what's the best way to get notified ONCE when all the queries have succeeded? #2440

Answered by TkDodo
blomm asked this question in Q&A
Discussion options

You must be logged in to vote

I think there must be something more simple. Do you really need to get the data from the cache? I would consider it done if all the queries are in success state, so something like:

const runQueries = useQueries(
    tables.map((table: string) => {
      return {
        queryKey: [
          "runs",
          {
            table
          },
        ],
        queryFn: fetchRunsForTable,
      };
    })
  );

const allFinished = runQueries.every(query => query.isSuccess)


useEffect(() => {
    if (allFinished) {
        // all the queries have executed successfully
    }
}, [allFinished])

problem is, you can't really depend on the data in your effect, because it would likely be a new ar…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@blomm
Comment options

Answer selected by blomm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants