Cursor Rule: React Optimization
optics/cursor-rule-react-optimizationFreeUtility
Cursor rule file for React optimization guidelines.
See it running
Open the demo on optics
optics.agusmayol.com.ar/components/cursor-rule-react-optimizationInstall it
npx shadcn@latest add https://optics.agusmayol.com.ar/r/cursor-rule-react-optimization.jsonSource
1---2description: Rules for modern React Optimization3globs: *4alwaysApply: false5---6# React Optimization Rules78## Core Principles910Optimize for real performance bottlenecks, not perceived ones. Profile before optimizing. Premature optimization adds complexity without guaranteed benefits.1112## Component Optimization1314Use React.memo for expensive pure components that receive the same props frequently. Avoid wrapping every component—this adds overhead.1516Implement useMemo for expensive calculations, not simple operations. Reserve for computationally intensive transformations, filtered/sorted large arrays, or complex object creations.1718Apply useCallback when passing callbacks to memoized children or when callbacks are dependencies in useEffect/useMemo. Don't use it everywhere.1920## State Management2122Keep state as local as possible. Lift state only when necessary for sharing between components.2324Avoid storing derived values in state. Calculate them during render or use useMemo for expensive derivations.2526Split large state objects into smaller, independent pieces to prevent unnecessary re-renders.2728Use state updater functions when new state depends on previous state to avoid stale closures.2930## Rendering Optimization3132Implement key props correctly in lists. Use stable, unique identifiers, never array indices for dynamic lists.3334Break large components into smaller ones. This enables more granular re-rendering and improves code organization.3536Use React.lazy and Suspense for code-splitting routes and heavy components.3738Avoid creating objects or functions in render. Define them outside the component or memoize them.3940## Event Handlers4142Bind event handlers in the component body or use arrow functions in class properties, not in JSX.4344Debounce or throttle expensive event handlers like scroll, resize, or input changes.4546## Lists and Virtualization4748Implement virtualization for long lists using libraries like react-window or react-virtual.4950Avoid inline arrow functions in list item props unless the list is small and static.5152## Context Optimization5354Split contexts by update frequency. Separate rarely-changing and frequently-changing values.5556Memoize context values to prevent unnecessary provider re-renders.5758Consider using multiple smaller contexts instead of one large context.5960## Images and Assets6162Lazy load images below the fold using native loading="lazy" or intersection observers.6364Serve appropriately sized images. Use responsive images with srcset.6566// … truncated
Files it writes
More from optics
All 79 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Cursor Rule: Back Endcursor-rule-back-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Bulk Processingcursor-rule-bulk-processing | optics | Utilities | Free | no deps | |
| Cursor Rule: Commits Conventioncursor-rule-commits-convention | optics | Utilities | Free | no deps | |
| Cursor Rule: Front Endcursor-rule-front-end | optics | Utilities | Free | no deps | |
| Cursor Rule: Generalcursor-rule-general | optics | Utilities | Free | no deps | |
| Cursor Rule: Web Interface Guidelinescursor-rule-web-interface-guidelines | optics | Utilities | Free | no deps | |
| Get strict contextget-strict-context | optics | Utilities | Free | no deps | |
| Use auto heightuse-auto-height | optics | Utilities | Free | no deps |
