Replies: 1 comment
-
Check #525 (comment), there is a solution to mutate your keys when you don't know the exact key and only a part of them |
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
-
I have this watchlist that the server returns and it contains products.
A
product.is_liked
indicates that the product is on the watchlist.Then I have a
useSearch
hook which also returns a list of products, where theis_liked
prop could be set.My problem is to keep both cached data in sync on the client.
When I modify the watchlist on the server, naturally the cached result of the
useSearch
hook does not know about that. So the still mounted search result items still show the stale data forproduct.is_liked
.I know I could do a global
mutate
on the search key, unfortunately I don't know the key because it is a compound key:useSearch(["/search", searchTerm, limit], (path, { searchTerm, limit})
So I not simply call the unbound `mutate("/search")?
I also experimented with a virtual data storage like this:
Where the watch list items and search result items would all use
useWatch
with their respective product id.However this did not work either.
Maybe I am just thinking to complicated or swr is not suited to solve such interdependencies.
Beta Was this translation helpful? Give feedback.
All reactions