__Notes
Zustand 參考指南
以計時器為範例
// src/store/useCounter.ts
import create from 'zustand';
interface CounterState {
count: number;
incrementCount: () => void;
decrementCount: () => void;
}
const useCounter = create<CounterState>((set) => ({
count: 0,
incrementCount: () => set((state) => ({ count: state.count + 1 })),
decrementCount: () => set((state) => ({ count: state.count - 1 })),
resetCount: () => set(() => ({ count: 0 })),
}));
export default useCounter;
在需要使用的檔案
import useCounter from './store/useCounter';
const { count, incrementCount, decrementCount } = useCounter();