when we set?
just like react: setState(prevState=>prevState+1)
set(prev => prev + 1)
but we need to have this option outside of store I want to use value or function to set a property from outside of store
you put the state and the action to change the state all inside the store when you create store export const useStore = create((set) => ({ value: true, toggleValue: () => set((state) => ({value: !state.value})) })) To change the state in another file, you use the action that's already in the store. const toggleZustandState = useStore(state => state.toggleValue); ... return <button onClick{toggleZustandState}>toggle</button>
Обсуждают сегодня