What is the best practice for using initial data from another query before the query was settled
Hi!
I have an expensive query that fetches all todo items and I also have an additional expensive query that fetches the todo of a single item.
I would like to fetch all todo items and then use them as initial data for each single query.
This will allow me to invalidate a single todo item without invalidating all todo items.
Following the blog by tkdodo on
initialData
I thought that the best approach for this issue is using the initialData
option but I mounted the query before all the todo items were fetched so this doesn't help me.
https://tkdodo.eu/blog/placeholder-and-initial-data-in-react-query
What is the best approach to solve this issue?
Should I mount the query only once I have the data from the todo items or perhaps there is a better way using react-query.
This is my solution using a useEffect
to set the query cache.
Placeholder and Initial Data in React Query
Learn about the different possibilities to avoid loading spinners in React Query.

0 Replies