npx skills add ...
npx skills add sergiodxa/agent-skills --skill frontend-react-best-practices
React performance optimization guidelines. Use when writing, reviewing, or refactoring React components to ensure optimal rendering and bundle patterns. Triggers on tasks involving React components, hooks, memoization, or bundle optimization.
npx skills add sergiodxa/agent-skills --skill frontend-react-best-practices
Performance optimization and composition patterns for React components. Contains 33 rules across 6 categories focused on reducing re-renders, optimizing bundles, component composition, and avoiding common React pitfalls.
Reference these guidelines when:
Import directly from source, avoid barrel files.
Load modules only when feature is activated.
Preload on hover/focus for perceived speed.
Use functional setState for stable callbacks.
Derive state during render, not in effects.
Pass function to useState for expensive initial values.
Use primitive dependencies in effects.
Subscribe to derived booleans, not raw values.
Extract expensive work into memoized components.
Hoist default non-primitive props to constants.
Don't wrap simple primitive expressions in useMemo.
Put interaction logic in event handlers, not effects.
Use startTransition for non-urgent updates.
Use refs for transient frequent values.
Use ternary, not && for conditionals with numbers.
Extract static JSX outside components.
Use content-visibility for long lists.
Animate wrapper div, not SVG element (for GPU acceleration).
Reduce SVG coordinate precision with SVGO.
Use inline script for client-only data to prevent flicker.
Suppress expected hydration mismatches.
Render browser-only components with ClientOnly and a fallback.
Use useHydrated for SSR/CSR divergence.
Prefer useTransition over manual loading states.
Place error boundaries at feature boundaries.
Use passive listeners for scroll/touch.
Version and minimize localStorage data.
Use useEffect only when absolutely necessary. Prefer derived state or event handlers.
Use named function declarations in useEffect for better debugging and self-documentation.
Don't add boolean props to customize behavior. Use composition instead.
Structure complex components as compound components with shared context.
Lift state into provider components for cross-component access.
Create explicit variant components instead of prop combinations.
Prefer children for composition. Use render props only when passing data back.
Avoid rigid configuration props; prefer composable children APIs.
Use TypeScript namespaces to combine component and its types for single-import access.
Important: Namespaces should only contain types, never runtime code.