Unsure if PersistQueryClientProvider is working with Next.js
Here is the code for my _app.js file:
7 Replies
foreign-sapphireOP•3y ago
I use the queryClient that I think I have persisted inside of a step in within a multi-step form. Here is how I use the queryClient to set defaultValues for this form:
The queryData from getQueryData doesn't persist on refresh and undefined is returned instead. I don't believe I have set up the
PersistQueryClientProvider correctly with Next.js and would like some assistance in ensuring that I do.absent-sapphire•3y ago
Can you try putting the persister creation in state as well? A reproduction would be good
foreign-sapphireOP•3y ago
Sure. I will upload a reproduction in a bit
foreign-sapphireOP•3y ago
Hi @TkDodo 🔮 , sorry for the delay. This is a link to a simple reproduction of the error I am running into: https://codesandbox.io/p/sandbox/persistqueryclientprovider-setup-bo2wob?file=%2Fpages%2Ftest.js&selection=%5B%7B%22endColumn%22%3A35%2C%22endLineNumber%22%3A4%2C%22startColumn%22%3A35%2C%22startLineNumber%22%3A4%7D%5D
persistQueryClientProvider setup
CodeSandbox is an online editor tailored for web applications.
absent-sapphire•3y ago
well the TestPage still renders while we're restoring the cache from localstorage, so the effect will also run. We've made sure that
useQuery respects that, but if you manually read from the cache, you have to keep that in mind as well. You can read from useIsRestoring() to see if we're in the process of restoring and either not render your component or delay the effect accordingly.absent-sapphire•3y ago
persistQueryClientProvider setup (forked)
CodeSandbox is an online editor tailored for web applications.
foreign-sapphireOP•3y ago
Understood. Thank you for your assistance.