agentleFS
LDKTCLDKTC/Agent-P-FullStack/skills/react/SKILL.md

react

Skill1 starsChanged 4 months agoMITView on GitHub

Write idiomatic, correct, and performant React — Rules of Hooks and dependency arrays, recognizing when an effect is the wrong tool, stable list keys, composition and state placement, controlled vs uncontrolled inputs, memoization judgment (useMemo/useCallback/React.memo only where a measured re-render cost justifies it), and avoiding data-fetching waterfalls or misplaced client-only code in SSR-capable setups. Use when package.json lists react, react-dom, or next as a dependency, when authoring or reviewing .jsx/.tsx component code, or when asked directly (Thai or English) to เขียนหรือตรวจโค้ด React ให้ถูกต้องและมีประสิทธิภาพ. Not a replacement for frontend-dev's framework-agnostic UI work or html-css's semantic/accessibility foundation — this is the React-specific expertise layer built on top of both.

30 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use app-renderer-systems, refactoring-analysis and 8 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.
  • pedronauckSkill

    app-renderer-systems

    Create, extend, or debug frontend domain modules organized under systems/. Covers adapters, Query hooks, local state, and public exports; excludes generic components and backend implementation.

    Also in 3 projects that use this

  • pedronauckSkill

    refactoring-analysis

    Audit code quality and architectural health or plan refactoring using Fowler code smells and techniques; write prioritized findings to docs/_refacs/. Excludes formatting, performance, and security audits.

    Also in 3 projects that use this

  • akornmeierSkill

    tailwindcss

    Guide for implementing Tailwind CSS - a utility-first CSS framework for rapid UI development. Use when styling applications with responsive design, dark mode, custom themes, or building design systems with Tailwind's utility classes.

    Also in 6 projects that use this

  • MindrallySkill

    prisma

    Expert in Prisma ORM with type-safe database operations and schema design

    Also in 4 projects that use this

  • joabgonzalezSkill

    express

    Express.js routing, middleware, and error handling. Trigger: When building REST APIs or server logic with Express.

    Also in 3 projects that use this

  • barisariburnuSkill

    tanstack

    Expert assistance for TanStack Router, Query (v5), and Table (v8). Use when users need help with file-based routing, type-safe navigation, data loading, search params, queries, mutations, optimistic updates, infinite queries, table state management, or debugging TanStack libraries.

    Also in 3 projects that use this

  • +1 more from pedronauck

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 0 are common, 2 are distinctive, and 14 are very specific to this project.

  • 0

    Common

    Most of the 23 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 14

    Very specific

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

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

    Check package.json for react, react-dom, or next, or the presence of .jsx/.tsx files, or a direct request for React code.

    line 17
  2. Very specific:

    If the task is markup semantics or accessibility rather than component behavior, that's html-css directly — it applies whether or not JSX …

    line 20
  3. Very specific:

    Don't silence exhaustive-deps to quiet the warning.

    line 32
  4. Very specific:

    Use a functional updater (setX(prev => ...)) when next state depends on previous state, to avoid stale closures in async or rapid handlers.

    line 34
  5. Very specific:

    Before writing useEffect, ask: is this actually derived state?

    line 39
  6. Distinctive:

    If nothing external is involved, the effect is almost always removable.

    line 55
  7. Very specific:

    Don't use key as a shortcut to force a remount unless a full remount is genuinely intended (e.g.

    line 64
  8. Very specific:

    Prefer composition (children, render props, slot props) over deep prop drilling or reaching for context early — context is for values …

    line 71
  9. Very specific:

    Default to no memoization — useMemo/useCallback/React.memo cost their own comparison and allocation.

    line 86
  10. Distinctive:

    Don't call hooks conditionally, in a loop, or after an early return.

    line 122
  11. Very specific:

    Don't add a useEffect to compute a value that's already derivable during render.

    line 123
  12. Very specific:

    Don't use the array index as key on a list that can reorder, filter, or splice.

    line 125
  13. Very specific:

    Don't leave an input half-controlled (value with no onChange, or a value that toggles to undefined).

    line 127
  14. Very specific:

    Don't add useMemo/useCallback/React.memo by default — unjustified memoization is often slower than the render it's avoiding.

    line 129
  15. Very specific:

    Don't fetch a child's data inside a useEffect that only fires after a parent fetch resolves — coordinate the fetch instead.

    line 131
  16. Very specific:

    Don't mark a component client-only just because it sits inside a React tree, and don't skip html-css's semantic/accessibility rules just …

    line 133

“Common” is measured: kept by at least 6 in 10 of the 23 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

frontend-dev's React-specific expertise layer: that agent is framework-agnostic and matches whatever's already in the project — this skill is the actual React knowledge it draws on when the framework happens to be React. skills/html-css/SKILL.md still applies underneath JSX — semantics, labels, landmarks, and keyboard/contrast rules don't stop mattering because the markup is generated by a component.

Step 1 — Confirm this is React work

Check package.json for react, react-dom, or next, or the presence of .jsx/.tsx files, or a direct request for React code. If none of that holds, stop — use frontend-dev for whatever framework is actually there. If the task is markup semantics or accessibility rather than component behavior, that's html-css directly — it applies whether or not JSX is involved.

Step 2 — Rules of Hooks and dependency arrays

  • Hooks are called only at the top level of a function component or a custom hook (named useXxx) — never inside if/for/switch, never after an early return, never in a nested callback. Call order must be identical every render; that's the whole mechanism hooks rely on.
  • The dependency array lists every reactive value the effect body reads — a missing dependency isn't an optimization, it's a stale-closure bug. Don't silence exhaustive-deps to quiet the warning; fix the actual cause.
  • Use a functional updater (setX(prev => ...)) when next state depends on previous state, to avoid stale closures in async or rapid handlers.

Step 3 — Effects: when they're the wrong tool

Before writing useEffect, ask: is this actually derived state? If a value can be computed straight from existing props/state, compute it during render (or wrap in useMemo if expensive) — don't useEffect + setState to mirror one value into another.

// Wrong: effect just to derive a value
const [fullName, setFullName] = useState('');
useEffect(() => setFullName(`${first} ${last}`), [first, last]);

// Right: derived during render, no effect needed
const fullName = `${first} ${last}`;

Effects are for synchronizing with something outside React — a subscription, a DOM API, a timer, a third-party widget, a network request. If nothing external is involved, the effect is almost always removable.

Step 4 — Keys and list correctness

  • Keys are a stable, unique id from the data, on the outermost element the mapped callback returns — never array index once a list can reorder, filter, or insert/remove; index keys reattach state (inputs, toggles, animations) to the wrong row after the list changes shape. Index-as-key is fine only for a genuinely static list.
  • Don't use key as a shortcut to force a remount unless a full remount is genuinely intended (e.g. resetting a form per entity id).

Step 5 — Composition, state placement, controlled inputs

  • Colocate state with the component that owns it; lift only once a sibling genuinely needs it, not pre-emptively "just in case."
  • Prefer composition (children, render props, slot props) over deep prop drilling or reaching for context early — context is for values genuinely global to a subtree (theme, auth, locale), not a shortcut around passing two props.
  • Context re-renders every consumer on every value change regardless of which slice it reads — split into narrower contexts or memoize the provided value; wrapping consumers in memo doesn't help, it guards against prop changes, not context changes.
  • Controlled (value+onChange) vs uncontrolled (ref+defaultValue) — pick one per input and stay consistent; a value that flips between a real value and undefined across renders breaks the contract and React warns about it.

Step 6 — Memoization judgment

  • Default to no memoization — useMemo/useCallback/React.memo cost their own comparison and allocation; add them only where a value must stay referentially stable (a dependency elsewhere, a prop into a memoized child) or a measured re-render is actually expensive.
  • Confirm with the React DevTools Profiler (or equivalent) that a component re-renders often with unchanged props and that its render is expensive before wrapping it in memo — not on habit.
  • Splitting a component so expensive work lives in a smaller subtree is often simpler and cheaper than memoizing the whole thing.

Step 7 — Data fetching and client/server boundaries

  • A child that only starts fetching after its parent's fetch resolves is a waterfall — fix with Promise.all/parallel queries or a fetch at a shared ancestor, not inside each leaf's own effect. Watch for the hidden case: a list renders, then each item fetches its own detail data in a useEffect — an N+1 waterfall.
  • On SSR/RSC setups (server components, loaders, a getServerSideProps-style function), fetch there instead of in a client effect — one server round trip beats N client ones.
  • Code touching window, document, localStorage, or other browser-only APIs must not execute during server render — guard it with the framework's client-boundary mechanism, not a crash-and-catch. Mark a component client-only because it needs a browser API or interactivity, not just because it sits inside a React tree.

Step 8 — Self-check before reporting done

Confirm no hook is called conditionally or after an early return, and every dependency array is complete. Confirm list keys are stable ids, not indexes, on anything that can reorder, and any memoization added is justified by a measured re-render cost, not habit. Confirm the JSX still holds up against html-css's structure/accessibility checks.

What not to do

  • Don't call hooks conditionally, in a loop, or after an early return.
  • Don't add a useEffect to compute a value that's already derivable during render.
  • Don't use the array index as key on a list that can reorder, filter, or splice.
  • Don't leave an input half-controlled (value with no onChange, or a value that toggles to undefined).
  • Don't add useMemo/useCallback/React.memo by default — unjustified memoization is often slower than the render it's avoiding.
  • Don't fetch a child's data inside a useEffect that only fires after a parent fetch resolves — coordinate the fetch instead.
  • Don't mark a component client-only just because it sits inside a React tree, and don't skip html-css's semantic/accessibility rules just because the markup is now JSX.

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.