react-best-practices
Skill2 starsChanged 9 months agoMITView on GitHub
Use when reviewing React component code during code quality review, when the diff contains .tsx or .jsx files, or when reviewing components that use React hooks, state management, or data fetching patterns
66 other projects use a version of this.
Adopted by
Most recently taken up by
- eea/eea.agent.skillstheir own version, first seen Nov 8, 2026
- amanuelmamo7/Skillstheir own version, first seen Nov 7, 2026
- drinkspiller/skillstheir own version, first seen Nov 6, 2026
- tylergibbs1/codewardentheir own version, first seen Nov 1, 2026
- poizoncoded/skillstheir own version, first seen Nov 1, 2026
- sreejithraman/SreeStacktheir own version, first seen Oct 27, 2026
Used with
Projects with it also use composition-patterns, python-best-practices 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.
eeaSkillcomposition-patterns
React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.
Also in 4 projects that use this
jefflesterSkillpython-best-practices
Python development best practices including PEP 8 style guidelines, type hints, docstring conventions, and common patterns. Use when writing or modifying Python code.
Also in 3 projects that use this
MicrosoftSkillplanning-with-files
**USE THIS FOR COMPLEX TASKS.** Implements Manus-style file-based planning for multi-step tasks. Creates task_plan.md, findings.md, and progress.md in .agent_cache/<task-name>/. Use when: implementing multiple APIs, refactoring modules, research tasks, or ANY task requiring >5 tool calls.
Also in 5 projects that use this
VercelSkillvercel-deploy
Deploy applications and websites to Vercel with a claimable preview. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment". No authentication required - returns preview URL and claimable deployment link.
Also in 3 projects that use this
MicrosoftSkillcode-quality
Statically check changed C# against the same deterministic rules github-code-quality[bot] runs on pull requests, so a contributor can fix likely findings before opening the PR and keep the bot's inline comments to a minimum. Activate when a contributor asks to "check code quality", "run code quality on my changes", "will the code quality bot complain", "pre-check before I open the PR", "code quality check", or similar. Scoped to C#. Reads the diff and compares it against the enumerated csharp-code-quality rule set below — no CodeQL download or build required. This is a fast approximation of a dataflow engine, not a reproduction; report accordingly. Does NOT apply fixes unless explicitly asked.
Also in 5 projects that use this
VercelSkillweb-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
Also in 10 projects that use this
- +1 more from microsoft
Other versions66 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 66
- mastra-ai/mastra★ 29ksame name
- openai/plugins★ 7.8ksame name
- ryokun6/ryos★ 1.3ksame name
- involvex/youtube-music-cli★ 477same name
- vercel/vercel-plugin★ 328same name
- mikeOnBreeze/cc-crossbeam★ 297same name
- typv/nest-turbo-starter★ 224same name
- AvivK5498/Beads-Kanban-UI★ 102same name
- mxyhi/token_proxy★ 94same name
- laguagu/claude-code-nextjs-skills★ 72same name
56 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- architecture-decision-recordsSkill
- boy-scout-ruleSkill
- domain-driven-designSkill
- functional-core-imperative-shellSkill
- git-commit-messageSkill
- revise-for-claritySkill
- ux-design-principlesSkill
- ux-prototypingSkill
- ux-visual-evaluationSkill
- visual-feedback-loopSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 4 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 56 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Check each section below. Flag violations as Important or Minor per the standard review severity levels.
- Very specific: line 72
Check package.json for the React version.
- Very specific: line 85
useFormStatusrule: Must be called from a child component rendered inside the <form>, not in the same component that renders the form. - Distinctive: line 98
Every interactive element must work with keyboard (Tab, Enter, Space, Escape, Arrow keys)
- Very specific: line 114
Use userEvent (simulates real user behavior: focus, keyboard, hover) not fireEvent (dispatches a single DOM event)
- Distinctive: line 118
NOT implementation details — internal state, hook calls, re-render counts, component instance methods
- Distinctive: line 122
If you're testing mock behavior instead of real behavior, the test is wrong
“Common” is measured: kept by at least 6 in 10 of the 56 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.
Files
React Best Practices for Code Review
Supplement to the standard code review checklist. Covers judgment calls that linters and static analysis cannot catch.
When to Use
During code review when the diff contains React code (.tsx, .jsx, or .ts files importing from "react").
Apply these checks after the standard code quality review, as an additional pass.
Review Checklist
Check each section below. Flag violations as Important or Minor per the standard review severity levels.
1. Component Responsibility & Size
A component is too large when it mixes concerns, not when it exceeds a line count.
Flag when a single component does more than one of:
- Renders UI (view layer)
- Contains business logic (data transformation, validation, calculations)
- Manages complex state interactions (multiple related
useState+useEffect) - Fetches data
The fix pattern:
- View logic stays in the component (JSX, conditional rendering, layout)
- Business logic moves to pure functions (sorting, filtering, formatting, validation). Pure functions are trivially testable without rendering.
- Complex state + effects move to custom hooks (
useOrders,useAuth,useSettings). A hook is "complex" when it combines multipleuseStatecalls that interact with each other or withuseEffect.
// BAD: all mixed in one component
function Dashboard() {
const [orders, setOrders] = useState([]);
const [sorted, setSorted] = useState([]);
useEffect(() => { fetch(/*...*/) }, []);
useEffect(() => { setSorted(orders.sort(/*...*/)) }, [orders]);
const formatPrice = (n: number) => /*...*/;
return <table>...</table>;
}
// GOOD: separated by responsibility
function Dashboard() {
const { orders, sort, sortField } = useOrders(); // custom hook: state + fetching
return <OrdersTable orders={orders} onSort={sort} sortField={sortField} />;
}
// sortOrders(), formatPrice() are pure functions in a utils file2. useEffect Misuse
Linters catch missing dependencies. They cannot catch unnecessary effects.
Flag these patterns:
| Pattern | Fix |
Effect computes derived state (useEffect + setState from other state) | Compute during render or useMemo |
| Effect resets state when a prop changes | Use key on the component instead |
| Chain of effects (A sets state, triggers B, triggers C) | Do the work in one event handler |
User-driven side effect in useEffect instead of event handler | Move to the handler that caused it |
| Effect without cleanup for subscriptions, timers, or fetch | Add cleanup function with AbortController |
useEffect is ONLY for synchronizing with external systems (subscriptions, timers, DOM manipulation, third-party widgets).
3. React Version-Appropriate Patterns
Check package.json for the React version. Review for patterns appropriate to that version.
React 19+ apps should use:
| Instead of | Use |
Manual loading/error/data state for fetches | <Suspense> boundaries + Server Components for data fetching |
onSubmit + useState for form submission state | useActionState for form action + state, useFormStatus for pending UI |
useEffect to resolve promises | use() hook |
Defensive React.memo, useMemo, useCallback | React Compiler handles memoization automatically. Only add manual memoization when a third-party library requires stable identity, or as an explicit useEffect dependency. |
useActionState signature reminder: (prevState, formData) => newState — first arg is previous state, not formData. Imported from "react", not "react-dom".
useFormStatus rule: Must be called from a child component rendered inside the <form>, not in the same component that renders the form.
4. Accessibility Beyond Linting
eslint-plugin-jsx-a11y catches static markup issues. These behavioral issues require judgment:
Focus management:
- Modal/dialog: trap focus inside, return focus to trigger on close
- Route changes in SPAs: announce new page to screen readers
- Form errors: move focus to error summary or first invalid field
- Success/error messages: use
role="alert"oraria-live="polite"so screen readers announce them
Keyboard navigation:
- Every interactive element must work with keyboard (Tab, Enter, Space, Escape, Arrow keys)
<div onClick>is never a button — use<button>(linter catches some, not all)- Custom sort controls, dropdowns, tabs need keyboard handlers
Color:
- Status indicators (error, success, pending) must not rely on color alone — add icons, text labels, or patterns
5. Testing Practices
Query priority (most to least preferred):
getByRole— validates accessibility at the same timegetByLabelText— best for form fieldsgetByText— for non-interactive contentgetByTestId— last resort only
Interaction:
- Use
userEvent(simulates real user behavior: focus, keyboard, hover) notfireEvent(dispatches a single DOM event)
What to test:
- What the user sees and does — rendered output, interaction results, accessible names
- NOT implementation details — internal state, hook calls, re-render counts, component instance methods
Mocking:
- Mock at the network boundary with MSW (Mock Service Worker), not by replacing
global.fetchor mocking component imports - If you're testing mock behavior instead of real behavior, the test is wrong
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
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.

