agentleFS
jimmypocockjimmypocock/cursor-rules/.cursor/rules/react.mdc

cursor-rules / rules

Cursor rule8 starsChanged 19 months agoMITView on GitHub

React Development Standards

The file

Show its rules and text

We split this react.mdc into the rules it gives an agent

51 rules. About 0 are common, 51 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈51

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use functional components with hooks instead of class components

    line 16
  2. Distinctive:

    Keep components focused on a single responsibility

    line 17
  3. Distinctive:

    Create small, reusable UI components

    line 18
  4. Distinctive:

    Use proper prop types with TypeScript

    line 21
  5. Distinctive:

    Create presentational/UI components separate from data containers

    line 23
  6. Distinctive:

    Follow the Rules of Hooks consistently

    line 26
  7. Distinctive:

    Use useState for component state management

    line 27
  8. Distinctive:

    Create custom hooks for reusable logic

    line 29
  9. Distinctive:

    Use useCallback for memoized callbacks

    line 30
  10. Distinctive:

    Use context hooks for global state access

    line 33
  11. Distinctive:

    Use local state for component-specific state

    line 36
  12. Distinctive:

    Use proper state management libraries for complex state

    line 38
  13. Distinctive:

    Keep state normalized and minimal

    line 39
  14. Distinctive:

    Use state update functions instead of direct assignment

    line 41
  15. Distinctive:

    Create proper state update patterns

    line 42
  16. Distinctive:

    Use React.memo for pure components

    line 46
  17. Distinctive:

    Use windowing for long lists (react-window/react-virtualized)

    line 48
  18. Distinctive:

    Use Suspense for async operations

    line 51
  19. Distinctive:

    Avoid unnecessary renders with proper dependencies

    line 53
  20. Distinctive:

    Use proper event handler naming (handleEventName)

    line 56
  21. Distinctive:

    Use synthetic events properly

    line 58
  22. Distinctive:

    Use debouncing/throttling for frequent events

    line 60
  23. Distinctive:

    Create controlled components for form elements

    line 62
  24. Distinctive:

    Keep side effects isolated in useEffect

    line 66
  25. Distinctive:

    Use async operations correctly in effects

    line 69
  26. Distinctive:

    Create service layers for external interactions

    line 72
  27. Distinctive:

    Use props for parent-to-child communication

    line 76
  28. Distinctive:

    Use context for deep component communication

    line 78
  29. Distinctive:

    Create proper component interfaces

    line 81
  30. Distinctive:

    Document component communication patterns

    line 82
  31. Distinctive:

    Use composition over deep prop passing

    line 83
  32. Distinctive:

    Use consistent styling methodology (CSS Modules, CSS-in-JS, etc.)

    line 86
  33. Distinctive:

    Use consistent naming conventions for styles

    line 90
  34. Distinctive:

    Use design tokens for consistency

    line 93
  35. Distinctive:

    Write unit tests for components

    line 96
  36. Distinctive:

    Create integration tests for component interaction

    line 97
  37. Distinctive:

    Test component behavior, not implementation

    line 99
  38. Distinctive:

    Use proper test selectors

    line 100
  39. Distinctive:

    Test error states and edge cases

    line 102
  40. Distinctive:

    Use semantic HTML elements

    line 106
  41. Distinctive:

    Test with screen readers

    line 110
  42. Distinctive:

    Use proper color contrast

    line 111
  43. Distinctive:

    Create proper fallback UIs

    line 117
  44. Distinctive:

    Create user-friendly error messages

    line 120
  45. Distinctive:

    Create proper loading and error states

    line 123
  46. Distinctive:

    Create logical folder structures

    line 127
  47. Distinctive:

    Use index files for cleaner imports

    line 128
  48. Distinctive:

    Use JSDoc comments for component props

    line 132
  49. Distinctive:

    Use React Router or similar for routing

    line 136
  50. Distinctive:

    Create authenticated routes when needed

    line 138
  51. Distinctive:

    Create route-level code splitting

    line 141

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “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
react.mdc
---
description: React Development Standards
globs: 
alwaysApply: false
---
---
Description: React Development Standards
Globs: **/*.tsx, **/*.jsx, **/*.ts, **/*.js, **/components/**/*, **/hooks/**/*, **/context/**/*
---

# React Development Standards
@base.mdc
@typescript.mdc

## Component Architecture
- Use functional components with hooks instead of class components
- Keep components focused on a single responsibility
- Create small, reusable UI components
- Implement proper component composition
- Separate UI components from container components
- Use proper prop types with TypeScript
- Structure components with a logical folder organization
- Create presentational/UI components separate from data containers

## Hooks Usage
- Follow the Rules of Hooks consistently
- Use useState for component state management
- Implement useEffect with proper dependencies
- Create custom hooks for reusable logic
- Use useCallback for memoized callbacks
- Implement useMemo for expensive calculations
- Apply useRef for persisted mutable values
- Use context hooks for global state access

## State Management
- Use local state for component-specific state
- Implement React Context for shared state
- Use proper state management libraries for complex state
- Keep state normalized and minimal
- Implement proper state initialization
- Use state update functions instead of direct assignment
- Create proper state update patterns
- Implement state persistence when needed

## Performance Optimization
- Use React.memo for pure components
- Implement proper key usage in lists
- Use windowing for long lists (react-window/react-virtualized)
- Implement proper loading and lazy states
- Apply code splitting with React.lazy
- Use Suspense for async operations
- Implement proper bundle optimization
- Avoid unnecessary renders with proper dependencies

## Event Handling
- Use proper event handler naming (handleEventName)
- Implement event handler functions efficiently
- Use synthetic events properly
- Apply proper event propagation control
- Use debouncing/throttling for frequent events
- Implement proper form submission handling
- Create controlled components for form elements
- Apply proper validation for user inputs

## Side Effects
- Keep side effects isolated in useEffect
- Clean up side effects properly
- Implement proper dependency arrays
- Use async operations correctly in effects
- Apply proper error handling for side effects
- Separate API calls from UI components
- Create service layers for external interactions
- Implement proper loading and error states

## Component Communication
- Use props for parent-to-child communication
- Implement callback props for child-to-parent communication
- Use context for deep component communication
- Apply proper prop drilling avoidance
- Implement event buses sparingly and carefully
- Create proper component interfaces
- Document component communication patterns
- Use composition over deep prop passing

## Styling Approaches
- Use consistent styling methodology (CSS Modules, CSS-in-JS, etc.)
- Implement responsive designs
- Create theme-aware components
- Apply proper style organization
- Use consistent naming conventions for styles
- Implement proper media queries
- Apply accessibility-friendly styles
- Use design tokens for consistency

## Testing
- Write unit tests for components
- Create integration tests for component interaction
- Implement snapshot testing judiciously
- Test component behavior, not implementation
- Use proper test selectors
- Mock external dependencies
- Test error states and edge cases
- Implement proper test coverage goals

## Accessibility
- Use semantic HTML elements
- Apply proper ARIA attributes
- Create keyboard-navigable components
- Implement proper focus management
- Test with screen readers
- Use proper color contrast
- Create accessible forms
- Implement proper error messaging

## Error Handling
- Implement error boundaries for component errors
- Create proper fallback UIs
- Apply graceful degradation
- Implement proper API error handling
- Create user-friendly error messages
- Log errors appropriately
- Implement retry mechanisms when appropriate
- Create proper loading and error states

## Code Organization
- Organize code by feature or domain
- Create logical folder structures
- Use index files for cleaner imports
- Implement proper barrel exports
- Apply consistent file naming conventions
- Create component documentation
- Use JSDoc comments for component props
- Implement proper code splitting

## Routing (if applicable)
- Use React Router or similar for routing
- Implement proper route organization
- Create authenticated routes when needed
- Apply proper route parameters
- Implement proper navigation guards
- Create route-level code splitting
- Apply proper loading states for routes
- Implement proper 404 handling

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.