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
-
Hi. First of all, thanks for providing us with such good libraries!
We are in the process of integrating both
react-query
andreact-location
in our product.And several questions arise.
One them is about the invalidation of a query from
react-query
inside areact-location
loader.I could setup a sandbox if needed but please allow me to briefly describe the use-case.
"posts"
is a route defined as:getPosts
method usesqueryClient.fetchQuery(postsQuery)
to retrieve a list of postsPostList
element usesto retrieve the posts from the loader.
With this configuration, all works fine … but here comes the question:
It seems that when the
PostList
is displayed, nothing is observing thepostsQuery
query in the cache.This seems legit since the
PostList
uses posts coming from the route loader.The problem is that if an invalidation of the
postsQuery
comes (for ex from a websocket), then thePostList
does not get refreshed.As a workaround, we replaced the
useSearch
with ausePosts
hook 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