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
wise-whiteOP•3w 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.
genetic-orange•3w ago
Sounds like you'd
setQueryData(['some-key'], oldData => ...)
for places that need a refreshed profile pictureinland-turquoise•3w 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.
wise-whiteOP•3w ago
is this invalidating this way redundant?