React + Zustand
Minimal hook-based store, no provider needed. This page shows exactly what pickstack adds to a React project for Zustand: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework react --modules zustand --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
zustand | ^5.1.0 | runtime |
New files
import { create } from "zustand";
interface CounterState {
count: number;
increment: () => void;
decrement: () => void;
}
export const useCounterStore = create<CounterState>()((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
decrement: () => set((state) => ({ count: state.count - 1 })),
}));
Changes to existing files
+import { useCounterStore } from "../store/useCounterStore";−import { useState } from "react"; export default function Counter() {+ const count = useCounterStore((state) => state.count);+ const increment = useCounterStore((state) => state.increment);+ const decrement = useCounterStore((state) => state.decrement);− const [count, setCount] = useState(0); return ( <div className="card"> <p className="count">{count}</p> <div className="row">+ <button type="button" className="btn" onClick={decrement}>− <button− type="button"− className="btn"− onClick={() => setCount((n) => n - 1)}− > -1 </button>+ <button type="button" className="btn" onClick={increment}>− <button− type="button"− className="btn"− onClick={() => setCount((n) => n + 1)}− > +1 </button> </div>⋯ 4 unchanged lines
Project files
.gitignoreREADME.mdindex.htmlpackage.jsonsrc/App.tsxsrc/components/Counter.tsxsrc/index.csssrc/main.tsxsrc/store/useCounterStore.tstsconfig.jsonvite.config.ts