一键导入
pmndrs-jotai
Jotai atomic state management library. Trigger on: atom creation, state management, React hooks, vanilla store, derived atoms, jotai utils/extensions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Jotai atomic state management library. Trigger on: atom creation, state management, React hooks, vanilla store, derived atoms, jotai utils/extensions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | pmndrs-jotai |
| description | Jotai atomic state management library. Trigger on: atom creation, state management, React hooks, vanilla store, derived atoms, jotai utils/extensions. |
| metadata | {"author":"topic-skill-generator","version":"1.0.0","source":"https://github.com/pmndrs/jotai"} |
Jotai is a minimal atomic state management library for React (2kb core). It provides primitive atoms (hold values) and derived atoms (compute from other atoms). Built with TypeScript, uses pnpm monorepo, Rollup for builds, Vitest for testing.
Tech stack: TypeScript, React 16–19, Rollup, Vitest, pnpm, ESLint, Prettier.
Key concept: Atoms are the unit of state. atom(value) creates a primitive atom, atom((get) => get(other) + 1) creates a derived/read-only atom. The vanilla store manages atom lifecycle; React hooks bridge atoms to components.
src/
vanilla/ # Framework-agnostic core (no React dependency)
atom.ts # atom() factory — creates primitive & derived atoms
store.ts # createStore() — manages atom values, subscriptions, dependencies
internals.ts # Internal store mechanics (reconciliation, dependency tracking)
utils/ # Vanilla utilities (atomFamily, selectAtom, etc.)
react/ # React bindings
Provider.tsx # React context provider wrapping a store
useAtom.ts # useAtom() — read/write hook
useAtomValue.ts # useAtomValue() — read-only hook
useSetAtom.ts # useSetAtom() — write-only hook
utils/ # React utilities (useHydrateAtoms, useReducerAtom, etc.)
babel/ # Babel/SWC plugins for devtools labels & React Refresh
index.ts # Public entry (re-exports atom + React hooks)
vanilla.ts # Public entry for jotai/vanilla
react.ts # Public entry for jotai/react
utils.ts # Public entry for jotai/utils
Data flow: Component → useAtom(atom) → reads/writes via store → store notifies subscribers → dependent atoms recomputed → component re-renders.
import { atom } from 'jotai'
// Primitive (read-write)
const countAtom = atom(0)
// Derived (read-only)
const doubledAtom = atom((get) => get(countAtom) * 2)
// Derived (read-write)
const derivedRW = atom(
(get) => get(countAtom) * 2,
(get, set, arg) => set(countAtom, get(countAtom) + arg)
)
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
const Counter = () => {
const [count, setCount] = useAtom(countAtom) // read + write
const doubled = useAtomValue(doubledAtom) // read only
const set = useSetAtom(countAtom) // write only
return <button onClick={() => set(c => c + 1)}>{count}</button>
}
import { atom } from 'jotai/vanilla'
import { createStore } from 'jotai/vanilla'
const store = createStore()
store.set(countAtom, 5)
store.get(countAtom) // 5
const unsub = store.sub(countAtom, () => { /* notify */ })
unsub()
import { atomFamily } from 'jotai/vanilla/utils'
const todoAtom = atomFamily((id) => ({ id, text: '', done: false }))
// Usage: todoAtom(1), todoAtom(2)
src/vanilla/utils/ (vanilla) or src/react/utils/ (React)src/vanilla/utils.ts or src/react/utils.tsdocs/utilities/tests/ mirroring the src structurepnpm run test:spec to verifytests/ that reproduces the bugsrc/pnpm run test:spec — all tests must passpnpm run fix (format + lint)fix(scope): description formatpnpm install
pnpm run build # produces dist/ with CJS, ESM, UMD
pnpm run test # format + types + lint + spec
pnpm run fix # auto-fix formatting/linting
benchmarks/your-bench.ts using benny../src/vanilla/atom.ts and ../src/vanilla/store.tsnpx tsx benchmarks/your-bench.ts| File | Purpose |
|---|---|
src/vanilla/atom.ts | atom() factory — the core primitive |
src/vanilla/store.ts | createStore() — state container with dependency graph |
src/vanilla/internals.ts | Internal reconciliation & subscription logic |
src/react/Provider.tsx | React context provider for the store |
src/react/useAtom.ts | Primary React hook for reading/writing atoms |
src/react/utils/useHydrateAtoms.ts | SSR atom initialization |
src/babel/preset.ts | Babel preset combining debug-label + react-refresh plugins |
package.json | Exports map defining jotai, jotai/vanilla, jotai/react, etc. |
rollup.config.mjs | Build config producing CJS/ESM/UMD bundles |
tsconfig.json | TypeScript config with path aliases for jotai/* |
set() or the setter from useAtom.src/vanilla/ must remain React-free.<Provider>.useAtom for write-only — use useSetAtom to avoid unnecessary re-renders.[DEV-ONLY] and [PRD-ONLY] prefixes to control environment-specific tests.# Install & setup
pnpm install
# Development
pnpm run test:spec # Run tests
pnpm run test:types # Type checking
pnpm run test:lint # Lint
pnpm run test:format # Format check
pnpm run build # Build all formats
pnpm run fix # Auto-fix lint + format
# Benchmarks
npx tsx benchmarks/run-all.ts
// Import paths
import { atom } from 'jotai' // main entry
import { atom } from 'jotai/vanilla' // vanilla only
import { useAtom } from 'jotai/react' // React hooks only
import { atomFamily } from 'jotai/vanilla/utils' // vanilla utils
import { useHydrateAtoms } from 'jotai/react/utils' // React utils
Conventional commits: feat:, fix:, refactor:, chore:, docs:, test: — with optional scope like fix(react):.