agentleFS
harshadmadayeharshadmadaye/OPM/skills/react-patterns/SKILL.md

react-patterns

Skill4 starsChanged 56 days agoMITView on GitHub

Provides idiomatic React 18/19 and Next.js App Router patterns covering hooks discipline, composition, state colocation, server/client boundaries, Suspense and error boundaries, forms, data fetching, list keys, effects hygiene, and measurement-first performance work. Use when writing, reviewing, or refactoring React components, custom hooks, or Next.js routes.

47 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use typescript-strict, testing-strategy and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MicrosoftSkill

    typescript-strict

    Enable TypeScript strict mode (strict, noImplicitAny, strictNullChecks, etc.) in a project and fix the resulting errors without weakening types, tests, or runtime behavior. Use when asked to "enable strict mode", "turn on TypeScript strict", "fix strict errors", or migrate a codebase to strict type checking.

    Also in 3 projects that use this

  • BlockSkill

    testing-strategy

    Guidelines for writing effective tests in this project

    Also in 4 projects that use this

  • LangChainSkill

    docker-patterns

    Best practices for Docker containerization and multi-stage builds

    Also in 4 projects that use this

  • MicrosoftSkill

    error-handling

    统一错误处理系统。在添加 API 端点、修改错误处理、添加前端 API 调用、编写错误相关测试时使用。

    Also in 5 projects that use this

  • Wania-KazmiSkill

    backend-patterns

    Backend architecture patterns, API design, database optimization, and server-side best practices. Use when building APIs, services, or server-side functionality.

    Also in 5 projects that use this

  • LangChainSkill

    database-migrations

    Database migration patterns and schema versioning

    Also in 4 projects that use this

  • +2 more from microsoft

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 43 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Always-true conventions (naming, hooks rules, state location, the server/client boundary, security) live in OPM's rule react/patterns.md …

    line 11
  2. Very specific:

    Read references/hooks-state-and-lists.md when writing hooks or effects, placing state, composing components, or rendering lists.

    line 51
  3. Very specific:

    Read references/server-data-and-forms.md when crossing the Server/Client boundary, fetching data, adding Suspense or error boundaries, or …

    line 52
  4. Very specific:

    Read references/performance-and-a11y.md when optimising renders or bundles, or checking accessibility.

    line 53

“Common” is measured: kept by at least 6 in 10 of the 43 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

React Patterns

React rewards code that keeps render pure, puts state where it is used, and reaches for optimisation only after measuring. This skill is the checklist for that.

Always-true conventions (naming, hooks rules, state location, the server/client boundary, security) live in OPM's rule react/patterns.md (.claude/rules/opm/react/ once installed, rules/react/ in the plugin). This skill keeps the patterns and worked examples.

When to use

  • Writing or modifying function components, custom hooks, or component trees.
  • Reviewing JSX/TSX diffs.
  • Choosing where state should live or how components should compose.
  • Working across Server and Client Components in the Next.js App Router.
  • Diagnosing slow renders, waterfalls, or oversized bundles.

Core rules

Render is a pure function of props and state. Derive during render; do not store derived values.

// Good
function Cart({ items }: { items: CartItem[] }) {
  const total = items.reduce((sum, i) => sum + i.price * i.qty, 0);
  return <span>{formatMoney(total)}</span>;
}

// Bad: an extra render, a chance to desync, and hidden data flow
function Cart({ items }: { items: CartItem[] }) {
  const [total, setTotal] = useState(0);
  useEffect(() => setTotal(items.reduce((s, i) => s + i.price * i.qty, 0)), [items]);
  return <span>{formatMoney(total)}</span>;
}

Side effects live in event handlers or useEffect, never in the render body.

Compose, do not inherit. children, slot props, and compound components cover every case.

Do not define components inside components. A new component type on every render remounts its subtree and loses state.

References

  • Read references/hooks-state-and-lists.md when writing hooks or effects, placing state, composing components, or rendering lists.
  • Read references/server-data-and-forms.md when crossing the Server/Client boundary, fetching data, adding Suspense or error boundaries, or building forms.
  • Read references/performance-and-a11y.md when optimising renders or bundles, or checking accessibility.

Review checklist

  • No derived state in useState + useEffect.
  • Every effect has a reason to exist and a cleanup if it subscribes.
  • Keys are stable ids; conditionals use ternaries where 0 could leak.
  • State lives at the lowest component that needs it.
  • "use client" is at the leaves, not the layout.
  • Server Actions authenticate and authorise internally.
  • Independent awaits run in parallel.
  • Memoisation is justified by a profile or removed.
  • Forms validate on the server; errors are announced (role="alert").

Related skills

  • opm:tdd-workflow - component behaviour tests with Testing Library before implementation.
  • opm:verification-before-completion (full gate) - build, tsc --noEmit, lint, tests before claiming done.
<!-- Adapted from affaan-m/ecc (MIT) -->

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.