pickstack

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 --yes
Customize in the configurator

Packages it adds

PackageVersionType
zustand^5.1.0runtime

New files

src/store/useCounterStore.ts
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

src/components/Counter.tsx (changed)
+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

Related templates