react-best-practices

Guides writing React components with correct Effect, ref, and composition patterns.

3|1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/firstsun-dev/skills --skill react-best-practices-firstsun-dev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: react-best-practices
Source: https://github.com/firstsun-dev/skills/tree/main/plugins/frontend-product-design/skills/react-best-practices
Command: npx skills add https://github.com/firstsun-dev/skills --skill react-best-practices-firstsun-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? React codebases often accumulate misuse of useEffect, refs, and state that causes bugs like unnecessary re-renders, stale data, and broken cleanup. This Skill provides decision rules and code patterns for writing idiomatic React components. ## Core Features & Use Cases - Effect Discipline: A decision tree for choosing between event handlers, render-time calculation, useMemo, key props, and Effects, with cleanup and dependency rules. - Ref and Hook Patterns: Guidance on ref callbacks, useImperativeHandle, useEffectEvent, and custom hook naming and design. - Component Composition: Patterns for controlled vs uncontrolled components, composition over prop drilling, compound components, and Context usage. - Use Case: When reviewing a .tsx file with chained useEffect calls, load this Skill to refactor them into derived state and a single event handler. ## Quick Start Review this React component using the react-best-practices skill and refactor any unnecessary useEffect calls.

Frequently Asked Questions about react-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use useEffect in React?▼

Use useEffect only to synchronize with external systems such as browser APIs, third-party non-React libraries, or window event listeners. Derived state, expensive calculations, and event responses should use render-time calculation, useMemo, or event handlers instead.

How do I reset component state when a prop changes in React?▼

Pass a key prop to the component instead of using an Effect to reset state. When the key changes, React unmounts and remounts the component, resetting all its state automatically without extra code.

Why does my React effect fire twice in development?▼

React intentionally remounts components in development to verify that effect cleanup works correctly. Fix the cleanup function so remounting is safe rather than suppressing the double-fire with a ref guard.

What is useEffectEvent and when should I use it?▼

useEffectEvent wraps non-reactive logic inside an Effect so values like theme or callback props do not become reactive dependencies. This prevents effects from re-running when unrelated values change, such as reconnecting a chat on theme change.

Should I use refs or state for values in React components?▼

Use refs for values that do not affect rendering, such as timer IDs or DOM node references, and never read or write ref.current during render. Use state for any value that the UI displays or depends on.