Access store state via .getState()
when using store context via useStore
/useStoreWithEqualityFn
#3029
Unanswered
MeanMangosteen
asked this question in
Q&A
Replies: 2 comments 15 replies
-
Does the fact we use a context here mean that it's inherently not possible to do this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
export const useCounterStoreApi = () => {
const counterStoreContext = useContext(CounterStoreContext)
if (!counterStoreContext) {
throw new Error(`useCounterStore must be used within CounterStoreProvider`)
}
return counterStoreContext
} |
Beta Was this translation helpful? Give feedback.
15 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.
-
When creating a vanilla store like so the
getState()
method exists on the store:However I am using Next.js app router and using the setup guide for SSR'ing, where you end up accessing the store like:
However for
useCounterStore
no longer had thegetState()
method. Is there a way to do this?Motivation for this is that I'm trying to imperatively get the store state once in a method without having to subscribe to updates/use a hook.
Beta Was this translation helpful? Give feedback.
All reactions