/bulletproof-react-skills:state-and-datafrom bulletproof-react-skills
State management and data-fetching conventions from bulletproof-react: component vs. application vs. server vs. form vs. URL state, a single shared API client instance, colocated request declarations paired with React Query hooks, and API/in-app error handling. Use when adding state, wiring up an API call, or handling request/render errors in a React app. Reach for this whenever you're about to decide "should this be useState or global state?", add a new fetch/mutation to a React app, wire up form validation, or figure out where a caught error should surface — e.g. "where should I put this modal's open/closed state?", "how do I fetch and cache this list from the API?", "the app crashed on one bad component and took the whole page down with it."
Ships in bulletproof-react-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Adapted from bulletproof-react @
9506629, MIT licensed. See ../../NOTICE.md for provenance and the re-pin workflow.
Don't default to one centralized store for everything — sort state by how it's used first, since that determines which tool is actually appropriate for it. Categorizing state this way keeps the app performant and keeps you from reaching for a global store when a local useState would do.
Scope state to the component that owns it, and pass it down as props only when a child actually needs it. Start local; only lift it up once something else in the tree genuinely requires it. Use:
Reach for application state only for things that are genuinely global — modals, notifications, color mode. Don't promote state to this layer by default; keep it as close as possible to the components that need it, or you'll end up with a bloated, hard-to-reason-about global store.
Good Application State Solutions:
Don't cache server-fetched data in a general state store like Redux — it's the wrong tool for this job. Use a dedicated cache library instead; it'll handle invalidation, refetching, and staleness far better than a hand-rolled store.
Good Server Cache Libraries:
Server Cache State Example Code
Use a form library rather than hand-rolling validation, error handling, and submission logic — it's a lot of surface area to get right on your own, and these libraries already cover it.
Forms in React can be controlled and uncontrolled.
Depending on the application needs, they might be pretty complex with many different fields that require validation.
Although it's possible to build a form using only React primitives, prefer one of these instead:
Wrap the library in your own abstracted Form component and input field components, adapted to the application's needs, rather than using the library's primitives directly everywhere.
Pair the form library with a validation library for client-side input validation:
When state should be shareable, bookmarkable, or reflect navigation (a dynamic param like /app/${dynamicParam}, or a query param like /app?dynamicParam=1), put it in the URL rather than component or application state. Use a routing solution like react-router-dom to read and manipulate it.
Create one pre-configured API client instance and reuse it everywhere, instead of constructing a new client per call site. Build it with the native fetch API or a library like axios, graphql-request, or apollo-client, with your shared config baked in once.
Don't declare API requests inline at the call site — define and export them separately, colocated with the feature that uses them. This keeps the codebase organized and makes every endpoint the app uses easy to track.
Every API request declaration should consist of:
Type the responses and let that typing flow down through the app — it's what gives you type safety on data coming back from the API.
API Request Declarations - Query - Example Code API Request Declarations - Mutation - Example Code
Add an interceptor to the API client to handle errors centrally — use it to fire notification toasts, log out unauthorized users, or trigger a token-refresh request, rather than handling these cases ad hoc at each call site.
API Errors Notification Example Code
Use React error boundaries, and place multiple of them at different points in the tree rather than wrapping the whole app in a single one. That way a failure in one area gets contained and handled locally instead of taking down the entire application.
Track production errors with a dedicated tool like Sentry rather than rolling your own — it reports issues that break the app along with the platform/browser context they occurred in. Upload source maps so errors point back to your actual source code, not the bundled output.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub dfadler/bulletproof-react-skills --plugin bulletproof-react-skills7 skills in this plugin
/components-and-stylingComponent and styling conventions from bulletproof-react: colocation,
avoiding nested render functions, container/presentation separation, and
composition-over-config for component APIs. Covers when to reach for a
fully-styled vs. headless component library, which styling solution fits
a given setup (including React Server Components constraints), and using
Storybook for isolated component development. Use this when designing a
new component's API, reviewing a component for prop bloat or nested
render functions, choosing a component library or styling approach for a
project, or when a request looks like "this component is taking too many
props, how should I split it up," "what component library should I use
for this dashboard," or "where should I put this piece of state/style so
it doesn't cause unnecessary re-renders."
/performancePerformance conventions from bulletproof-react: code splitting,
component/state update optimization, list virtualization, image
optimization, and bundle analysis. Use when a React app feels slow or before
shipping a feature that renders large lists or heavy assets. Reach for this
whenever you're about to add a route, decide where a piece of state should
live, render a list of unknown or large size, or add images — and whenever
a request mentions phrasing like "this page feels slow", "why is this
component re-rendering so much", or "how should I load these images".
/project-standardsProject standards from bulletproof-react: ESLint/Prettier/TypeScript config,
absolute imports, pre-commit hooks, and CI conventions. Use when setting up
tooling for a React project or reviewing its lint/format/type configuration.
Reach for this whenever asked to "set up linting for a new React project,"
"configure absolute imports so I stop seeing ../../../," "add a pre-commit
hook to run lint and type-check," or "review this project's ESLint/Prettier/
tsconfig setup" — or when enforcing consistent file/folder naming conventions
across a codebase.
/project-structureProject structure conventions from bulletproof-react: what lives in src/,
the app/assets/components/features/hooks/lib/stores/testing/types/utils
layout, and how features are organized to stay unidirectional. Use when
scaffolding a new React project, deciding where a new file belongs, reviewing
a PR that imports across feature boundaries, or setting up ESLint import
restrictions — for example "where should this component/hook/API call live",
"should this be shared or feature-scoped", or "is this cross-feature import
okay".
/securitySecurity conventions from bulletproof-react: token storage and
authentication for SPAs, authorization patterns, and other client-side
hardening practices. Use when implementing auth, authorization checks, or
handling sensitive data in a React app. Reach for this whenever a task
involves deciding where to store a JWT after login, wiring up route/component
guards so only certain roles can see a feature, restricting an action (like
deleting a comment) to its owner, or reviewing a PR that touches
authentication/authorization code — for example "where should I store the
auth token", "how do I hide this button from non-admins", "only the comment
author should be able to delete it", or "is this login flow XSS-safe".
/testingTesting strategy conventions from bulletproof-react: when to reach for a
unit vs. integration vs. e2e test, and the recommended tooling (Vitest,
Testing Library, Playwright, MSW) for each. Use this whenever adding tests
to a React app, deciding what kind of test a piece of code actually needs,
or reviewing a PR's test coverage — especially when the default has been
"add a unit test" without considering whether an integration test would
give more real confidence. Reach for this when the user asks things like
"what kind of test should this component have", "should I mock the API
for this test", or "how do I set up e2e tests for this app".