Zustand and Next - Persisting state between client components across page reloads #2897
-
In the Zustand docs related to Next.js is the following:
I understand that Zustand should not be used on the server (due to shared state between requests), and I understand that rendering the store per request avoids this issue, however I'm unclear on whether there is a good pattern to use when we want to share state between client components across requests / page loads. I can think of two ways of achieving this, but I'd really appreciate some guidance on whether either of these is the best approach. My use-case is that I have some ephemeral state that I don't need/want to save to the server, but I do need to be able to share between client components on different pages. The approaches I can think of are:
Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
@Undistraction in a nutshell:
|
Beta Was this translation helpful? Give feedback.
-
I'm away from my laptop until Monday but happy to share what I have then.
Are you using TypeScript?
…On Sat, 14 Dec 2024, 18:47 Pál András Csokán, ***@***.***> wrote:
Thanks for replying so quickly. Would definitely be helpful to add some
guidance for achieving shared state between pages to the Zustand Next docs
<https://zustand.docs.pmnd.rs/guides/nextjs>, as it definitely reads as
if store-per-request is the only supported approach, and I imagine its a
very common requirement.
Hey,
May I ask for some help on how to create a store provider in Nextjs?
—
Reply to this email directly, view it on GitHub
<#2897 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABHNUJNXB25I5DWDWRVEPD2FR4KNAVCNFSM6AAAAABTR2MDOGVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNJWHAYTKNY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
@Undistraction in a nutshell:
Root Layout
Layout
of that page