Describe the bug#
Hi,
First off, thank you for this. Game changer. I love it.
I'm running into this issue where any usage of my custom ReactQuery hook will cause a component to render twice. The first render is with undefined data, then the second render with the correct data. Even with it cached.
Is anyone else running into this issue? Please see CodeSandbox
Your minimal, reproducible example#
https://codesandbox.io/embed/upbeat-minsky-6xf1im?fontsize=14&hidenavigation=1&theme=dark
Steps to reproduce#
- Add react query to a component.
- Watch it render once undefined.
- Then watch it render again with the data.
Expected behavior#
I expect it to render once with data.
How often does this bug happen?#
Every time
Screenshots or Videos#
Platform#
macOS
TanStack Query version#
4.24.10
TypeScript version#
No response
Additional context#
CodeSandbox is what I have on my machine. I just changed the API URL.
So I'm guessing this about the persistence plugin and you'd expect only one render after you have data persisted and reload the page? You're not mentioning that in the steps to reproduce, so this is just a guess.
The persistence plugin restores asynchronously, but we'll still render the component while the restore is happening. This is crucial for server-side-rendering to work. The query renders in
loadingstate, but withfetchStatus: idle. If you want to stop your app from rendering, you can check withuseIsRestoringif that is in progress and rendernullor something instead of your App:then, your App will only render once.