Replies: 1 comment 1 reply
-
|
Instead of using React Location as the source of truth, keep fetching and using your data from React Query and merely use React Location's loaders to |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. First of all, thanks for providing us with such good libraries!
We are in the process of integrating both
react-queryandreact-locationin our product.And several questions arise.
One them is about the invalidation of a query from
react-queryinside areact-locationloader.I could setup a sandbox if needed but please allow me to briefly describe the use-case.
"posts"is a route defined as:getPostsmethod usesqueryClient.fetchQuery(postsQuery)to retrieve a list of postsPostListelement usesto retrieve the posts from the loader.
With this configuration, all works fine … but here comes the question:
It seems that when the
PostListis displayed, nothing is observing thepostsQueryquery in the cache.This seems legit since the
PostListuses posts coming from the route loader.The problem is that if an invalidation of the
postsQuerycomes (for ex from a websocket), then thePostListdoes not get refreshed.As a workaround, we replaced the
useSearchwith ausePostshook which usesuseQuery(postsQuery)and thus make PostList an observer of the query, which then gets refreshed on query invalidation.This "seems" ok since with both implementations, the query cache is used.
But it would be great to have your feedback on this. Is there something we missed? Should react-location "loader/route element" be somehow an observer of a query when react-query is used?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions