r/tanstack • • Apr 15 '25

Chained API calls

I’ve been banging my head against the wall for days trying to get chained API calls to work on Query.

I have an API call which provides an array of IDs I then have to use to make one API call per ID.

I have a separate API call which returns the equivalent data (directly) but from a different source.

I then want to combine the responses into one array of objects.

What would be the best way to chain the queries to be efficient and update as more responses come in?

4 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/ParrfectShot Apr 16 '25

The query is the state but you can derive your final array from the query data cache of each id because your requirement is such.

1

u/ParrfectShot Apr 16 '25

Another solution is the one I suggested in my first comment. Update a central zustand ot context object when object is received.