react-best-practices
What it does
This skill gives guidance for writing and reviewing React code with good performance. It covers avoiding loading delays, keeping bundles small, and reducing unnecessary re-renders.
When to use it
- ✓When you are writing new React components or data fetching code.
- ✓When you are reviewing React code for speed or size problems.
- ✓When your React app loads slowly or re-renders too often.
Skill link
https://github.com/mastra-ai/mastra/blob/main/.claude/skills/react-best-practices/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“My React dashboard is slow to load. Review the components and tell me the biggest performance fixes.”
5 new skills a week. 1 minute to read.
How it works
The agent reviews the code against a prioritized set of rules, starting with the highest-impact ones such as loading waterfalls and bundle size. It then suggests changes in order of impact.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
React Best Practices
Overview
Routing and priority guide for React performance and quality, containing 27 rules across 9 categories. Rule files hold the detailed explanations, examples, review smells, and impact metrics.
When to Apply
Reference these guidelines when:
- Writing new React components
- Implementing data fetching
- Reviewing code for performance issues
- Refactoring existing React code
- Optimizing bundle size or load times
Priority-Ordered Guidelines
Rules are prioritized by impact:
| Priority | Category | Impact |
|---|---|---|
| 1 | Eliminating Waterfalls | CRITICAL |
| 2 | Bundle Size Optimization | CRITICAL |
| 3 | Client-Side Data Fetching | MEDIUM-HIGH |
| 4 | Re-render Optimization | MEDIUM |
| 5 | Rendering Performance | MEDIUM |
| 6 | JavaScript Performance | LOW-MEDIUM |
| 7 | Component Structure | MEDIUM-HIGH (maintainability) |
| 8 | Testing | MEDIUM-HIGH (correctness) |
| 9 | Type Safety | HIGH |
Quick Reference
Critical Patterns (Apply First)
Eliminate Waterfalls:
- Use
Promise.all()for independent async operations (async-parallel)
Reduce Bundle Size:
- Avoid barrel file imports, import directly from source (
bundle-barrel-imports) - Defer non-critical third-party libraries (
bundle-defer-third-party)
Medium-Impact Patterns
Client-Side Data Fetching:
- Use Tanstack Query for automatic request deduplication (
client-request-dedupe) - Dependent query params are the value or
undefined, never| nullor a fake fallback; narrow at the caller so hooks stay strict, or guard withskipTokenwhen the hook must accept an optional param (client-request-dedupe)
Re-render Optimization:
- Use lazy state initialization for expensive values (
rerender-lazy-state-init) - Apply
startTransitionfor non-urgent updates (rerender-transitions) - Keep UI handlers plain; use Effect Events only for effect-fired logic (
rerender-useeffect-function-calls) - Never reset state with
useEffect; lift the discriminant and remount the branch (rerender-no-useeffect-state-reset) - Never add
useMemooruseCallback; leave memoization decisions to developers with profiler evidence (rerender-no-usememo-usecallback) - Never call
setStateduring render or insideuseEffect; derive during render or move state ownership to an intermediate component (rerender-no-setstate-in-render-or-effect)
Component Structure:
- One domain component/hook per file, one responsibility each — split bloated components (
structure-single-responsibility) - Keep component, hook, function, and utility APIs narrow: split oversized props, arguments, and return objects into focused units composed at the component level; wrapping the same values in one object is not a fix (
structure-narrow-apis) - Use PascalCase components for JSX-returning helpers; keep lowercase helpers for non-JSX values (
structure-component-naming) - Derive props/params instead of accepting a value computable from another arg (
structure-derive-dont-duplicate) - Extract complex derived logic into named locals plus predicates or pure helpers with early returns: oversized conditions, nested ternaries, ternaries that compute instead of picking (multi-line branches, or an
ascast re-asserting what the condition tested), fallback chains, andlet-based render prep are code smells, in render prep and in hook options, request builders, config maps, and reducers alike (structure-complex-derived-logic) - Pick the view with early
ifguards but keep the layout wrapper in one place — branch a body component, don't ternary or duplicate the shell (structure-early-return-render-branches) - For a fixed set of items, write one component per item with explicit props that owns its data and loading — don't map a config-object array onto a component shape (
structure-composition-over-config) - When a domain component fetches data, render through a pure layout component that positions slots, and branch the slot contents between skeletons and resolved sub-domain components (
structure-data-fetching-layout)
Testing:
- BDD tests that d
FAQ
What gets fixed first?
The biggest impact areas, such as eliminating waterfalls and reducing bundle size.
Does it cover testing too?
Yes. It includes guidance on testing and type safety along with performance.
Is this only for one framework?
It is for React code in general, with examples and rules that apply to typical React apps.
Details
Original description by the author
React performance optimization guidelines from Mastra Engineering. This skill should be used when writing, reviewing, or refactoring React code to ensure optimal performance patterns. Triggers on tasks involving React components, data fetching, bundle optimization, or performance improvements.
repo: mastra-ai/mastra
Popularity
- GitHub stars
- 29k
- Ranking position
- #9365
- License
- —
- Updated
- 11/2/2026
Comments
- …
More skills from this repository
debugging-difficult-bugs
29kHelps your agent debug a hard bug by logging what the real program does at runtime, instead of guessing from tests alone.
mastra-frontend
29kHelps your agent build app screens with the Mastra playground design system by combining its ready-made components, rather than styling from scratch.
pr-explainer
29kHelps your agent turn a pull request into a clear, self-contained HTML page that explains the change to reviewers.
pr-splitter
29kHelps your agent break a large, messy pull request into smaller, reviewable pull requests while keeping the original work safe.
Similar skills
angular-developer
280kHelps your agent create Angular code and give project structure advice. Useful for starting new projects, creating code parts, or improving performance and accessibility.
frontend-a11y
280kHelps your agent make web interfaces accessible to everyone. It ensures websites and apps work well with screen readers and keyboard navigation.
frontend-patterns
280kHas your agent apply modern patterns in frontend development. It optimizes performance, manages state, and follows best practices in React and Next.js.