Cache update
Is it normal to call several custom functions to update the cache after a mutation when using TanStack Query, or is that considered ineffective?
4 Replies
quickest-silverOP•3mo ago
For example, if the current user updates their profile picture, and some posts are tied to that user's data but the user isn't directly part of the query keys then those posts won't automatically reflect the updated profile picture. In such cases, it's often necessary to manually update or invalidate multiple related queries using custom functions.
ugly-tan•3mo ago
Sounds like you'd
setQueryData(['some-key'], oldData => ...)
for places that need a refreshed profile picturerival-black•3mo ago
That's why invalidation is preferred, as you can target all relevant queries with one line of code and they will be eventually consistent.
quickest-silverOP•3mo ago
is this invalidating this way redundant?