Replies: 1 comment
-
Though we never got any thoughts on this here, we did get one answer to the same question posted on Discord, from @TkDodo , prominent React Query blog-author, suggesting going with the invalidation approach: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm curious if there is a preferred method of invalidating dependent queries, as my coworker and I took two different approaches based on our understanding of the documentation.
We have two queries both wrapped in hooks, one called
favorites
and the otheroffers
. Thefavorites
data is an array of items the user can add or remove from, whereas theoffers
data is generated by the backend based on the items the user adds to theirfavorites
.The desired functionality is that when a user adds or removes a
favorite
, theoffers
data is refetched.One approach was to add the
favorites.data
property as a dependency of theoffers
query key, with the understanding that iffavorites.data
changed, theoffers
query would refetch.The other approach was to invalidate the dependent query from the
onSuccess
handler of the mutation functions in thefavorites
hook.Is either approach more consistent with the React Query paradigm? Is there another route we may both be overlooking? Any help is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions