Using persistant Zustand store within Next.js hydrating Zustand before SSR #2788
Unanswered
christianjuth
asked this question in
Ideas
Replies: 1 comment 9 replies
-
|
@christianjuth you can't hydrate on server side only on client side. I encourage you to read our SRR and Hydration guide. |
Beta Was this translation helpful? Give feedback.
9 replies
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.
-
TLDR; I think Zustand, when persisting within a Next.js app should let you hydrate Zustand server side and client side
I had the idea to persist my Zustand store using cookies. This means I can read/write to the cookie client side, and Server Side Rendered (SSR) my Next.js site with Zustand already hydrated, without worrying about a SSR hydration html mismatch.
I created a demo that allows you to select a sort preference for a list. The preference is stored and persisted via Zustand, and the list is SSR with the list already sorted.
I'm not sure if I'm doing a good job explaining, but I would love to get your thoughts:
Beta Was this translation helpful? Give feedback.
All reactions