Replies: 4 comments 9 replies
-
You can always manually keep the
|
Beta Was this translation helpful? Give feedback.
-
Hi @tannerlinsley, I wonder if you have any insights into this topic? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
maybe try some normalize cache solution ? |
Beta Was this translation helpful? Give feedback.
-
What I usually do is that if I have an |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone! I'm sure this must've been mentioned somewhere already, but cannot find any related discussions.
It's pretty common in REST APIs to have an endpoint returning Entity A and another endpoint returning an array of entities of type A with some additional information. As an example, imagine you have a specific search result (with keys
text
,id
) and an array of results for the autocomplete dropdown, but this response also includes information about which filters are applied.As it is, I use 2
react-query
cache keys for each one of these calls, let's call thementity
andentity-list
. All is good until Entity A becomes stale, e.g. when you update it. As an example, imagine a user suggesting edits to the search result becausetext
contained incorrect information. What I'd do right now is update the local cache of Entity A (entity
) with the returned data from the update call. This works, but only if I ensure my array of results (entity-list
) gets invalidated.Here's my question. Invalidating related queries is tedious, error-prone, and wasteful because we already have the fresh data in
entity
. Is there a best practice for handling this issue? In Redux, you'd keep each entity in Redux store accessible byid
. Then you just need to update that object and all your selectors will continue working with the latest data. What's thereact-query
equivalent of this functionality?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions