1---2name: react-testable-storybookable3description: Scaffolds React components that are jointly unit-testable and Storybook-ready with MSW and clear seams. Use this skill when creating new components that need tests and stories from day one. Do not use when/for end-to-end browser automation (use agent-browser) or journey-level Storybook docs without scaffolding (use storybook-journeys).4---56# React Testable & Storybookable78## Critical rules910- A component may depend on **props** and **injectable context** only — never network, router, or an unoverridable global store.11- Testability and storybookability are the same property: shared fixtures, shared MSW, shared providers.12- Leaf/presentational stays props-only; push fetching into a thin container.13- Hooks surface explicit `idle` / `loading` / `success` / `error`; React Query uses a key factory.14- One MSW handler/fixture set backs Vitest, Storybook, and optional local mocks.15- Ship the trio: `Component.tsx` + `Component.stories.tsx` + `Component.test.tsx`.16- Export props types; type stories from them. `QueryClient` in tests has `retry: false`.17- Before scaffolding harness files or WRONG/CORRECT samples, read the matching resource below.1819## Workflow20211. Classify tier: leaf (props), container (hooks + providers), or provider/boundary.222. Keep API/router out of the leaf; pass data and callbacks as props.233. Before writing harness or MSW boilerplate, read [references/scaffold.md](references/scaffold.md).244. Add `renderWithProviders` (theme, router, QueryClient with retries off) and shared fixtures/handlers with failure injection + store reset.255. For containers that read context, add a test-only provider implementing the same `state` / `actions` / `meta` contract.266. Scaffold the file trio: `scripts/scaffold-component.sh <ComponentName> [target-dir]` (see `--help`).277. Stories: Default, Empty, Loading, Error; handlers via `fn()`. Import shared fixtures.288. Wire Storybook `preview` with MSW + providers + a11y addon.299. For WRONG/CORRECT prop, hook, and story patterns, read [references/examples.md](references/examples.md).3031## Resources3233- [references/examples.md](references/examples.md) — prop-driven, keys/hooks, MSW, trio, test provider. Read when implementing.34- [references/scaffold.md](references/scaffold.md) — copy-paste harness: utils, MSW, providers, decorators. Read when setting up a project.35- [scripts/scaffold-component.sh](scripts/scaffold-component.sh) — generates the component/stories/test trio. Run with `--help` for usage; refuse overwrite.3637## Validation3839- [ ] Leaf depends only on props + injectable context40- [ ] Explicit status / key factory for hooks41- [ ] Trio present; stories cover Default, Empty, Loading, Error with `fn()`42- [ ] Stories and tests share fixtures; containers use `renderWithProviders` + MSW43- [ ] `QueryClient` retry off; store reset between tests44- [ ] Storybook preview wires MSW + providers + a11y4546## Constraints4748- Page-level flows belong in `storybook-journeys`. Visual tokens in `ui-design-principles`. Architecture baseline in `react-development`.49- Adjacent: `result-types`, `testing-strategy`, `validation-boundary`. Prefer composition patterns over boolean-prop sprawl.