Persisting state across Next.js pages

Does anyone know the best way to persist state across pages, I want to have a cart with items that persists on all pages, I have tried zustand but no luck.
3 Replies
zendev
zendev14mo ago
Reacts context api can be used to store state values globally. If you’re talking solely about rendering a UI component across all pages, simply render that component in the highest part of your component tree (I believe this is _app.tsx in the pages dir, not sure what the file is called for app dir)
fdawg
fdawgOP14mo ago
Thanks for reply, I ended up by using zustand with persistance , works perfectly!
ATOMowy_grzyb
ATOMowy_grzyb14mo ago
you have a SPA that maintains its state across pages (unless you use <a> links which reload the page) so you can put your shared state in the app, which persists between pages
Want results from more Discord servers?
Add your server