Skip to content

NextJS and zustand #2326

Feb 12, 2024 · 6 comments · 18 replies
Discussion options

You must be logged in to vote

@HasanMothaffar sure, let me explain you two scenarios:

On nextjs any component is rendered/initialized twice, one on the backend and one the client.

When is safe but:

  • not recommended: when you use a global store, the initial state is the same on both (server and client) and the initial state doesn't depends on something on the server, but keep in mind if something changed and now your initial state depends on something on the server, now you are not safe anymore and you need to use the recommended way
  • recommended: when you use a app/page/route store, the initial state is the same on both (server and client) and the initial state doesn't depend on something on the server

As you can see …

Replies: 6 comments 18 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@tyler-audio
Comment options

@alexander-densley
Comment options

@Vee-ble
Comment options

@dbritto-dev
Comment options

@alexander-densley
Comment options

Comment options

You must be logged in to vote
5 replies
@dbritto-dev
Comment options

@HasanMothaffar
Comment options

@dbritto-dev
Comment options

Answer selected by dbritto-dev
@dbritto-dev
Comment options

@HasanMothaffar
Comment options

Comment options

You must be logged in to vote
4 replies
@dbritto-dev
Comment options

@TimurKr
Comment options

@dbritto-dev
Comment options

@dbritto-dev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants