Zustand question

const useStore = create((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
decrement: () => set((state) => ({ count: state.count - 1 })),
}));
const useStore = create((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
decrement: () => set((state) => ({ count: state.count - 1 })),
}));
i know that we should get count by useStore((state)=>state.count) right? But what about increment and decrement function, cant i just use useStore.getState.increment? It is not like the inrement function re-render is needed for reactivity, there is nothing that depends on it?
Solution:
okay i am dumb, should have read docs better
Jump to solution
2 Replies
choco
chocoOP4w ago
i ask this, because it seems nobody uses getState when using functions such as increment and decrement, so i feel like i might be wrong
Solution
choco
choco4w ago
okay i am dumb, should have read docs better

Did you find this page helpful?