RTK Query - Collection and single entity sync #1342
Replies: 3 comments
-
Just wanted to chime in that I had the same question/problem and also thought it was a common use case! Asked my question here. |
Beta Was this translation helpful? Give feedback.
-
FYI I replied to @maximforever's question here, which looks like it is applicable to this question also. In regards to these specific questions:
In many cases it's fine to refetch the whole list when just one item is expected to have changed, but if you want to avoid that request, you can use manual cache updates such as optimistic updates to update the existing cache entry in the list directly, either by using:
For this solution, you wouldn't use
I'm not sure exactly what you're referring to as an issue here. If you're using the provided list query hook with |
Beta Was this translation helpful? Give feedback.
-
I'm glad I found this discussion, as I'm currently trying to migrate my setup from Also, sharing the data has the benefit that the data is always in sync (as I don't want to always refetch every time In my previous setup, it was pretty straightforward to have all the data shared, as I created my state to be pretty much an object of Products that's keyed on ID. I'm not sure what the best option for me is. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys, I'm looking into migrating our codebase to use RTK Query however theres a pretty simple use case that I would like to understand how you guys would handle it:
With this kinda of API and with 2 different components that could appear at the same time:
ComponentA (A list of products that fetches all the products to display them)
ComponentB (A side panel that fetches a single product to display it's details)
How would you proceed to make it so that when ComponentB fetches a product the ComponentA updates if this specific product changed so that it's not confusing for the end user?
I'm sure this is a pretty common use case and I just wanted to know how you guys would do it!
Beta Was this translation helpful? Give feedback.
All reactions