How to persist/save form data when navigating to and from the same page/going back in history?
Unanswered
European pilchard posted this in #help-forum
European pilchardOP
Still new to NextJS and web dev so I'm trying to figure this out. Would you just use
For example: If I have
useContext? Or is that only for SPAs? My situation is that I have multiple pages accessible via different routes/urls, and one of them has a form. I would like to persist user values if they half-way enter the values on the form and they click away, go back in history, etc unless they do a full reload of the page which would then reset all the form values to the initial state. Is there caching involved with this, or what are my options in managing this?For example: If I have
/gallery page and a page on /contact which contains the form, and a user enters some or all values on the /contact page, but does not submit the form, and they navigate to the /gallery page and then either go back in browser history or click on the link back to /contact page, I would like the data the entered to still be there. When they submit the form or hard refresh/reload the page on /contact, I would like those form values to reset to whatever the initial state is.2 Replies
useContext is not only for SPA's and is an option here, you also have localStorage and sessionStorage, personally I would choose localStorage/sessionStorage because it doesn't require a whole context provider just for this one feature.Honestly, sessionStorage sounds perfect for this, since you said you want it to wipe on page refresh