Zustand 4 can't use store outside react #1204
Replies: 4 comments 2 replies
-
|
@mgscreativa I think you should do import createStore from 'zustand/vanilla';
const appContextStore = createStore((set) => ({
clientURL: '',
setClientURL: (clientURL) => set({ clientURL }),
firstLoad: true,
setFirstLoad: (firstLoad) => set({ firstLoad }),
}));
export default appContextStore;Have you tried it yet? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @adrianotadao If I do that, ¿will it break my appContextStore if I use it in my react components? In other words, If I implement the store like you suggest, ¿will I still be able to use that store in react components and still get components to re render on store changes? Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
We're also using vanilla store because accessing stuff outside of React and using useStore breaks a lot of stuff. Because with previous syntax we used this: But now if we use useStore, we don't have the option to pass a selector inside, we get immediately our defined store state. How should we proceed here? Thx! |
Beta Was this translation helpful? Give feedback.
-
|
I am able to access store values outside of react component by using But the issue here is that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! following the advise here https://github.com/pmndrs/zustand#using-zustand-without-react I'm trying to use my zustand appContextStore outside react (in a helper.js file)
My deps are:
"react": "18.0.0",
"react-native": "0.69.4",
"zustand": "^4.0.0",
This is my appContextStore,js:
Then, this is my helper.js file:
This is the error generated, it seems that something about react is still needed...
Beta Was this translation helpful? Give feedback.
All reactions