Skip to content
Discussion options

You must be logged in to vote

Cool. Incidentally, I have written about this exact use case in my blog: https://tkdodo.eu/blog/practical-react-query :)
The idea is to take the data returned from useQuery and use it as a fallback to calculate the local state, which will take precedence as soon as the user has made some input. I've refactored your example to this approach: https://codesandbox.io/s/wandering-dust-yzpbf?file=/src/App.js

You will instantly benefit from background updates, (which you can further tweak to disable if you have local state already), and the loading spinner will not be shown if data already exists in the cache.

I would suggest to use the ReactQueryDevtools - they help tremendously when using useQ…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@ryanmk54
Comment options

@ryanmk54
Comment options

@TkDodo
Comment options

@ryanmk54
Comment options

Comment options

You must be logged in to vote
1 reply
@ryanmk54
Comment options

Answer selected by ryanmk54
Comment options

You must be logged in to vote
2 replies
@TkDodo
Comment options

@shipstar
Comment options

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