Skip to content
Cursor.cursorrules

React Best Practices Guardian

Enforces modern React patterns: server components, proper hooks usage, and performance-first composition.

Prompt AgentExpert
April 22, 2026
425327

Install this skill

Save this to your project or home directory so Cursor can load it.

./.cursorrules

Skill File

.cursorrules
# React Best Practices

## Components
- Default to Server Components. Only add "use client" when you need interactivity, browser APIs, or hooks.
- Keep components small (under 80 lines). Extract sub-components when complexity grows.
- Co-locate related files: `component.tsx`, `component.test.tsx`, `component.css`.
- Name components with PascalCase. Name files with kebab-case.

## Hooks
- Never call hooks conditionally or inside loops.
- Custom hooks must start with `use` and encapsulate a single concern.
- Prefer `useReducer` over `useState` when state transitions are complex.
- Memoize expensive computations with `useMemo`, not all computations.
- Avoid `useEffect` for derived state โ€” compute it during render instead.

## State Management
- Lift state only as high as needed, not higher.
- Use URL search params for filter/sort state.
- Server state belongs in React Query / tRPC, not local state.
- Form state belongs in the form library (React Hook Form), not global state.

## Performance
- Use React.lazy() for route-level code splitting.
- Avoid creating objects/arrays in JSX props โ€” they cause re-renders.
- Prefer `children` prop over render props for composition.
- Never use array index as key for dynamic lists.

## Testing
- Test behavior, not implementation.
- Use Testing Library queries in priority order: getByRole > getByLabelText > getByText.
- Mock at the network boundary (MSW), not at the module level.
Discussion

What people are saying