Replies: 7 comments 34 replies
-
Thanks for asking!
I'm hoping something like this would work: const defaultValue = { ... }
const useFooStore = create((set => ({ ... }))
useFooStore.getSererState = () => defaultValue How's it? |
Beta Was this translation helpful? Give feedback.
-
any updates? |
Beta Was this translation helpful? Give feedback.
-
no updates? :) I saw this document: https://github.com/pmndrs/zustand/blob/bf9d0922fe9292c2399b9594eafe9304016b52d9/docs/guides/initialize-state-with-props.md and thought maybe I can make it easier: I'm not sure if I did it right. it would be great if any of you can check it and give some idea :) |
Beta Was this translation helpful? Give feedback.
-
@dai-shi @himself65
const useCountStore = create(getDefaultValue, (set)=>{
// ctx is placeholder for any data you want from or the first parameter can a object handled by user
const defaultValue = getDefaultValue(ctx); // { count: 10 }
return {
...defaultValue,
resetMethod: () => set({count: 0})
}
}) |
Beta Was this translation helpful? Give feedback.
-
I think we should move the discussion here.
If @knajjars can't provide a reproduction, can anyone follow? cc @charkour |
Beta Was this translation helpful? Give feedback.
-
@himself65, thanks for reporting this! I was also confused that @dai-shi, I propose we deprecate |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I see there's a field called
getServerState
, but I don't see any usage of this APIzustand/src/react.ts
Line 38 in 49dcec0
If we support like this, that will help SSR on
next.js
Upstream: #1145
Beta Was this translation helpful? Give feedback.
All reactions