Index of every page on this site: llms.txt
All skills
grahamcrackers avatar

/bulletproof-react-patterns

@ca83de4
Run it yourself

Bulletproof React architecture patterns for scalable, maintainable applications. Covers feature-based project structure, component patterns, state management boundaries, API layer design, error handling, security, and testing strategies. Use when structuring a React project, designing application architecture, organizing features, or when the user asks about React project structure or scalable patterns.

Use this Skill: https://skilld.dev/gh/grahamcrackers/skills/bulletproof-react-patterns

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesstate-management.md

≈930 tokens on demand. Your agent reads this file only when SKILL.md points to it.

State Management

Divide state into categories based on usage rather than storing everything centrally.

State Categories

State Type Description Solutions
Component State Local to a component, passed as props to children useState, useReducer
Application State Global UI state (modals, notifications, theme) Context + hooks, Zustand, Jotai, Redux Toolkit, XState
Server Cache State Remote data cached on the client TanStack Query, SWR, Apollo Client, URQL, RTK Query
Form State Form inputs, validation, submission React Hook Form, Formik, React Final Form
URL State Data in the address bar (params, query strings) React Router, URL search params

Component State

Start by defining state within the component. Elevate to a higher level only if needed elsewhere.

const [isOpen, setIsOpen] = useState(false);

Use useReducer when a single action should update multiple pieces of state.

Application State

Localize state as closely as possible to the components that need it. Avoid globalizing state prematurely.

Good options:

  • Zustand — minimal, hooks-based
  • Jotai — atomic, great for frequent granular updates
  • Redux Toolkit — structured, excellent DevTools
  • XState — state machines for complex workflows
  • React Context + hooks — built-in, best for low-velocity data (themes, user info)

Use use-context-selector if Context causes performance issues (most state libraries have selectors built in).

Server Cache State

Never copy query data into useState — use the query result directly.

// Don't do this
const { data } = useUsers();
const [users, setUsers] = useState(data); // stale copy

// Do this
const { data: users } = useUsers(); // always fresh

Good options:

Form State

Create abstracted Form and input field components that wrap the library and adapt to your application:

// components/ui/form/form.tsx — wraps React Hook Form
// components/ui/form/input.tsx — wraps form input primitives

Integrate with validation libraries like Zod or Yup.

Forms can be controlled or uncontrolled — choose based on need.

URL State

Use routing solutions to access and control URL parameters:

// /app/discussions/:id
const { id } = useParams();

// /app?page=2&sort=newest
const [searchParams] = useSearchParams();

URL state is ideal for filters, pagination, active tabs, and shareable views.

Key Principles

  • Don't mix server and client state.
  • Start local, elevate state only when necessary.
  • Don't rush to Context — consider lifting state up or composition first.
  • For high-frequency updates, consider atomic state libraries (Jotai) over Context.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill is an architectural guide for React development, providing best practices for project structure, state management, and testing. It contains exclusively educational content and code examples with no executable or malicious scripts.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    1/11 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at ca83de4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago

README badge

README badge for grahamcrackers/skills/bulletproof-react-patterns