How to define actions at module level, external to the store when using Next.js store configurations? #2454
-
I am following this guide(Setup with Next.js) to set up Here is my set up: - 1) Provider using
|
Beta Was this translation helpful? Give feedback.
Answered by
dbritto-dev
Jul 14, 2024
Replies: 1 comment 2 replies
-
Unfortunately, you can't define actions at module level with context. You need something like this: export const useBearStoreActions = () => {
const store = useContext(BearStoreContext);
if (!store) throw new Error(`useBearStore must be use within Provider`);
return {
incrementBearCount: store.getState().incrementBearCount,
};
}; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@karangarg45 actually, it's possible but you need to pass the store to your store action.
The implementation would be something like this: