agentleFS
jaansokkjaansokk/cursor_tools/.cursor/skills/react-dev/SKILL.md

react-dev

Skill1 starsChanged 9 months agoMITView on GitHub

React 18+ development: components, hooks, state, effects, TypeScript, Tailwind CSS, performance, accessibility, testing, and security. Use when building or modifying React UI, state management, hooks/effects, forms, styling, or frontend tests.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

44 rules. 0 are common, 32 are distinctive, and 12 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 32

    Distinctive

    This author's own choices. Worth a look.

  • 12

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this whenever you are asked to:

    line 16
  2. Distinctive:

    Add/repair accessibility (semantic HTML, keyboard support, ARIA)

    line 21
  3. Distinctive:

    Write or update frontend tests (React Testing Library)

    line 22
  4. Distinctive:

    Correctness: no hook rule violations, no state mutation, no effect loops, no controlled/uncontrolled switching

    line 28
  5. Distinctive:

    Safety: avoid XSS footguns; never inject untrusted HTML

    line 33
  6. Distinctive:

    Do not perform side effects during render (no subscriptions, no direct DOM mutation, no network calls).

    line 65
  7. Distinctive:

    Keep event handlers as the primary place where user actions trigger state updates.

    line 66
  8. Distinctive:

    Call Hooks only at the top level of React components or custom hooks.

    line 70
  9. Distinctive:

    Never call Hooks inside loops, conditions, or nested functions.

    line 71
  10. Very specific:

    Prefer enabling and respecting eslint-plugin-react-hooks (rules-of-hooks + exhaustive-deps).

    line 72
  11. Distinctive:

    Prefer the smallest state that can drive the UI:

    line 76
  12. Distinctive:

    Avoid redundant/derived state (compute during render or memoize if expensive).

    line 77
  13. Distinctive:

    Avoid deeply nested state.

    line 78
  14. Distinctive:

    Keep a single source of truth.

    line 79
  15. Distinctive:

    When multiple components must stay in sync:

    line 80
  16. Very specific:

    Consider useReducer for complex update logic.

    line 82
  17. Distinctive:

    Treat props/state as immutable snapshots.

    line 86
  18. Distinctive:

    Update objects/arrays by creating new ones (spread, map/filter, or Immer if already used).

    line 87
  19. Distinctive:

    Do not mutate values read from state and then call setState with the same reference.

    line 88
  20. Very specific:

    Use useEffect when synchronizing with an external system, e.g.:

    line 92
  21. Distinctive:

    Don't use effects to orchestrate your app's internal data flow.

    line 96
  22. Distinctive:

    Always declare the full dependency list.

    line 97
  23. Distinctive:

    Avoid using refs to replace state for UI rendering.

    line 107
  24. Very specific:

    Use stable IDs from data for key.

    line 111
  25. Very specific:

    Avoid array indices as keys when items can reorder/insert/delete (it breaks state preservation and causes UI glitches).

    line 112
  26. Very specific:

    Never generate keys during render (e.g., Math.random()).

    line 113
  27. Distinctive:

    Never switch an input between controlled and uncontrolled across renders.

    line 119
  28. Very specific:

    Use React.ComponentProps<"button"> / ComponentPropsWithoutRef for wrapper components.

    line 126
  29. Very specific:

    Avoid any; prefer explicit unions and narrowing.

    line 127
  30. Distinctive:

    Keep prop types readable; don't over-genericize until needed.

    line 128
  31. Distinctive:

    Prefer structural fixes over micro-optimizations:

    line 135
  32. Distinctive:

    Avoid passing "new" object/function props to memoized children unless needed.

    line 137
  33. Distinctive:

    Use memoization tools intentionally:

    line 138
  34. Distinctive:

    Prefer semantic HTML ("right element for the right job") before ARIA.

    line 149
  35. Very specific:

    Ensure every interactive control has an accessible name (visible label, aria-label, or aria-labelledby).

    line 150
  36. Distinctive:

    When building custom widgets, follow the WAI-ARIA Authoring Practices patterns.

    line 154
  37. Distinctive:

    Use Testing Library's principles:

    line 160
  38. Distinctive:

    Test the app like a user uses it.

    line 161
  39. Very specific:

    Prefer queries by role + accessible name (getByRole, findByRole).

    line 162
  40. Distinctive:

    Avoid testing implementation details (DOM structure, internal state, private methods).

    line 163
  41. Very specific:

    Prefer @testing-library/user-event over low-level fireEvent for realistic interactions.

    line 164
  42. Very specific:

    Avoid dangerouslySetInnerHTML.

    line 170
  43. Distinctive:

    Only render trusted content or sanitize it with a well-reviewed sanitizer.

    line 171
  44. Distinctive:

    Follow OWASP XSS prevention guidance.

    line 174

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

When to use this skill

Use this whenever you are asked to:

  • Build or refactor React components, hooks, or UI flows
  • Fix bugs involving state, effects, rendering, or controlled inputs
  • Improve performance (unnecessary re-renders, slow lists, heavy computations)
  • Work with Tailwind CSS styling or responsive design
  • Add/repair accessibility (semantic HTML, keyboard support, ARIA)
  • Write or update frontend tests (React Testing Library)

For UI/styling work that requires high design quality, also read the UI Design skill at .cursor/skills/ui-design/SKILL.md.

Outcome targets

  • Correctness: no hook rule violations, no state mutation, no effect loops, no controlled/uncontrolled switching
  • Maintainability: clear component boundaries, minimal state, readable data flow
  • Type safety: strict TypeScript at all boundaries — no any
  • UX + A11y: semantic HTML first; predictable focus and keyboard behavior
  • Performance: measure before optimizing; optimize the right bottleneck
  • Safety: avoid XSS footguns; never inject untrusted HTML

Stack and tooling

  • React 18+ — functional components, hooks, concurrent features
  • TypeScript — strict typing, generics, discriminated unions
  • Tailwind CSS — utility-first styling, responsive design, design tokens
  • Vite — fast dev server, build config, env handling
  • State management — Zustand, React context, local state (pick the right level)
  • Testing — React Testing Library, user-event, vitest/jest

Coding standards

  1. TypeScript strict — type all props, callbacks, state. Avoid any.
  2. Functional components only — no class components.
  3. Tailwind for styling — no CSS modules or inline style objects unless absolutely necessary.
  4. Small, composable components — one responsibility per component. Extract early.
  5. Minimal state — derive in render what you can. Don't duplicate data across state slices.
  6. Accessible by default — semantic HTML, keyboard nav, visible focus, ARIA when needed.
  7. No side effects in render — effects are for external synchronization only.

Best-practice rules

A) Components and Hooks must be pure

  • Render functions must be pure and idempotent: same inputs (props/state/context) -> same JSX.
  • Do not perform side effects during render (no subscriptions, no direct DOM mutation, no network calls).
  • Keep event handlers as the primary place where user actions trigger state updates.

B) Follow the Rules of Hooks

  • Call Hooks only at the top level of React components or custom hooks.
  • Never call Hooks inside loops, conditions, or nested functions.
  • Prefer enabling and respecting eslint-plugin-react-hooks (rules-of-hooks + exhaustive-deps).

C) State modeling: keep it minimal and coherent

  • Prefer the smallest state that can drive the UI:
    • Avoid redundant/derived state (compute during render or memoize if expensive).
    • Avoid deeply nested state; normalize when it grows.
    • Keep a single source of truth.
  • When multiple components must stay in sync:
    • Lift state up to the closest common parent.
    • Consider useReducer for complex update logic; combine with Context when passing deeply.

D) Never mutate props/state

  • Treat props/state as immutable snapshots.
  • Update objects/arrays by creating new ones (spread, map/filter, or Immer if already used).
  • Do not mutate values read from state and then call setState with the same reference.

E) Effects are for external synchronization only

Use useEffect when synchronizing with an external system, e.g.:

  • Browser APIs (timers, observers), subscriptions, manual DOM work, network (when not handled by a framework/data layer)

Rules:

  • Don't use effects to orchestrate your app's internal data flow.
  • Always declare the full dependency list; avoid "lying" dependency arrays.
  • Implement cleanup for subscriptions/timers/listeners.
  • Expect Strict Mode to run an extra setup/cleanup cycle in development; your effect should be resilient.

F) Refs are for "escape hatches"

Use useRef for:

  • Holding mutable values that shouldn't trigger renders (timeouts, previous values, instance handles)
  • Accessing DOM nodes (focus, measurement) sparingly

Avoid using refs to replace state for UI rendering.

G) Lists: keys must be stable

  • Use stable IDs from data for key.
  • Avoid array indices as keys when items can reorder/insert/delete (it breaks state preservation and causes UI glitches).
  • Never generate keys during render (e.g., Math.random()).

H) Forms: pick controlled vs uncontrolled and stick to it

  • Controlled inputs (value + onChange) when you need validation, conditional UI, or instant feedback.
  • Uncontrolled inputs (defaultValue / refs / FormData) for simpler forms.
  • Never switch an input between controlled and uncontrolled across renders.

TypeScript

  • Type props, callbacks, and event handlers at component boundaries.
  • Use React.ComponentProps<"button"> / ComponentPropsWithoutRef for wrapper components.
  • Avoid any; prefer explicit unions and narrowing.
  • Keep prop types readable; don't over-genericize until needed.

Performance guidance

  • Measure first (React DevTools Profiler) before optimizing.
  • Prefer structural fixes over micro-optimizations:
    • Split large components; colocate state near where it's used.
    • Avoid passing "new" object/function props to memoized children unless needed.
  • Use memoization tools intentionally:
    • memo to skip re-renders when props are stable
    • useMemo for expensive calculations
    • useCallback when function identity stability matters (prop to memoized children / hook deps)
  • Be mindful with Context:
    • Context updates re-render consumers; keep provider values stable and consider splitting contexts by concern.

Accessibility

  • Prefer semantic HTML ("right element for the right job") before ARIA.
  • Ensure every interactive control has an accessible name (visible label, aria-label, or aria-labelledby).
  • Ensure keyboard accessibility:
    • Tab order makes sense
    • Focus is visible and managed for dialogs/menus
  • When building custom widgets, follow the WAI-ARIA Authoring Practices patterns.

Testing

  • Use Testing Library's principles:
    • Test the app like a user uses it.
    • Prefer queries by role + accessible name (getByRole, findByRole).
    • Avoid testing implementation details (DOM structure, internal state, private methods).
  • Prefer @testing-library/user-event over low-level fireEvent for realistic interactions.

Security

  • Avoid dangerouslySetInnerHTML. If you must render HTML:
    • Only render trusted content or sanitize it with a well-reviewed sanitizer.
  • Use defense-in-depth:
    • Configure CSP where possible.
    • Follow OWASP XSS prevention guidance.

Common failure modes (fast triage)

SymptomLikely causeFix
Infinite render/effect loopEffect sets state + deps cause re-runMove logic to render derivation or fix deps
Stale closuresEffect/handler reads old stateEnsure deps are correct or use functional updates
"Rendered fewer hooks"Hooks inside condition/loopRefactor so hooks are unconditional
Controlled/uncontrolled warningvalue flips between undefined and definedInitialize state and keep consistent
List UI glitchesUnstable keysFix keys to stable IDs

Sources

React (official)

Accessibility

Testing

Security

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.