zodiak
zodiak16mo ago

What would be considered best practice for getting data and invalidating queries?

I have a really simple task management app (doing it to learn stuff). Tasks are grouped in projects and have tags. I opted to load all projects, including the tasks and the tags on the tasks with a single query. When I add a new task or a tag, what would be the recommended way to update the data? - Invalidate the query to the big procedure and reload everything? - Separate the loading the data into different queries? - There is a way to invalidate only part of the big query? - Something else?
1 Reply
David
David16mo ago
In case you are still looking for the answer, you could use optimistic updates. https://tanstack.com/query/v4/docs/react/guides/optimistic-updates
Optimistic Updates | TanStack Query Docs
When you optimistically update your state before performing a mutation, there is a chance that the mutation will fail. In most of these failure cases, you can just trigger a refetch for your optimistic queries to revert them to their true server state. In some circumstances though, refetching may not work correctly and the mutation error could ...

Did you find this page helpful?