How to persisted data on index page when navigating back from a detailpage
In my Next.js project I implemented
useInfiniteQuery on an overview page to list blogs. The next thing I want to achieve is being able to restore all the blogs that have been fetched after reading a blog and coming back to the overview.
Should I use persistQueryClient? Or am I understanding this wrong.6 Replies
fascinating-indigo•4y ago
"coming back" from where? After the app has been closed, or after you've been on a different page in the same app?
adverse-sapphireOP•4y ago
Like when I click on a blog in the list. Read the blog and navigate back tot the index page using the browser back button
I have these 2 pages:
/blogs
/blogs/slug
/blogs is where I have the infinity scroll
When I go from /blogs to /blogs/slug back to /blogs I want to have the same data shown as when I left /blogs
fascinating-indigo•4y ago
Oh yeah, next is currently ... not very good at seeding client caches. See: https://twitter.com/tkdodo/status/1558752788393476096
Dominik 🇺🇦 (@TkDodo)
I can't believe there is no real solution in @nextjs for this: https://t.co/1RltC0OR9O
Consider:
- You prefetch page 1 of an infiniteQuery on the server
- You load more pages on the client
- navigate away and back
- gSSP will run again, fetch page 1 and overwrite the client cache
Twitter
adverse-sapphireOP•4y ago
Oh wow, crazy that there's no real solution for this (yet). I hope they will release this new router soon. Thanks anyways!
fascinating-indigo•4y ago
getInitialProps is the best solution for now. trpc uses that under the hood, too
typical-coral•4y ago
do you have an example for this. I am currently having similar issue