Can't get preserveState and preserveScroll to work #2359
Unanswered
russyc
asked this question in
Help (React)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I'm experimenting/learning with inertiajs using react (and rails on the backend), but I can't get
preserveState
to work.Here's part of
InertiaExample.tsx
that the rails installer creates, with an addedLink
component:and here is the About.tsx component:
When I increment the count on /inertia-example, then click the link to /about and back again, I thought the count would be preserved but it isn't. It's the same for scroll position and
preserveScroll
. I can add a large margin to the top of the example page and scroll down, but when I visit/about
and come back, the scroll resets.I've also tried replacing
useState
withuseRemember
but that has no effect. Is there something I'm doing wrong? Do I need to do anything special in the controller? Currently it's just this:Beta Was this translation helpful? Give feedback.
All reactions