A function to create a derived Zustand store from stores
npm install derive-zustand



A function to create a derived Zustand store from stores
``bash`
npm install zustand derive-zustand
`tsx
import { create, useStore } from 'zustand';
import { derive } from 'derive-zustand';
const useCountStore = create<{ count: number; inc: () => void }>((set) => ({
count: 0,
inc: () => set((state) => ({ count: state.count + 1 })),
}));
const doubleCountStore = derive
const useDoubleCountStore = () => useStore(doubleCountStore);
const Counter = () => {
const { count, inc } = useCountStore();
const doubleCount = useDoubleCountStore();
return (
Examples
The examples folder contains working examples.
You can run one of them with
`bash
PORT=8080 pnpm run examples:01_counter
``and open