Skip to content
Discussion options

You must be logged in to vote

When you're talking about global state, you do mean client state, because react-query already is a global server state manager. Call useQuery with the same key twice and you'll get the data.

while you certainly can do it, I don't think you should, for the following reasons:

  1. react-query is an async state manager, and you want something synchronous. Even if you return a static value like () => 5 from the queryFn, it's still being converted to a Promise, so you'll get one render cycle where your state is loading and data is undefined. In your example, you are working around this by setting initialData and staleTime: Infinite, so the queryFn is actually never called.
  2. You're opting out of all…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tncbbthositg
Comment options

@iamravisingh
Comment options

@AbobakarSadeeq
Comment options

Answer selected by tncbbthositg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants