Index of every page on this site: llms.txt
All skills
alleneubank avatar

/react-best-practices

@2921eb8
Run it yourself

Use when reading or writing React components (.tsx, .jsx files with React imports).

Use this Skill: https://skilld.dev/gh/alleneubank/claude-code/react-best-practices

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈26 tokens for metadata: the name and description. ≈791 when used: this file. ≈3k more on demand in 1 file.

Description uses 1.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈106 characters, or 1.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

React Best Practices

Pair with TypeScript

When working with React, always load both this skill and typescript-best-practices together. TypeScript patterns (type-first development, discriminated unions, Zod validation) apply to React code.

Core Principle: Effects Are Escape Hatches

Effects let you "step outside" React to synchronize with external systems. Most component logic should NOT use Effects. Before writing an Effect, ask: "Is there a way to do this without an Effect?"

Decision Tree

  1. Need to respond to user interaction? Use event handler
  2. Need computed value from props/state? Calculate during render
  3. Need cached expensive calculation? Use useMemo
  4. Need to reset state on prop change? Use key prop
  5. Need to synchronize with external system? Use Effect with cleanup
  6. Need non-reactive code in Effect? Use useEffectEvent
  7. Need mutable value that doesn't trigger render? Use ref

When to Use Effects

Synchronizing with external systems: browser APIs (WebSocket, IntersectionObserver), third-party non-React libraries, window/document event listeners, non-React DOM elements (video, maps).

When NOT to Use Effects

  • Derived state — calculate during render
  • Expensive calculations — use useMemo
  • Resetting state on prop change — use key prop
  • Responding to user events — use event handlers
  • Notifying parent of state changes — update both in the same event handler
  • Chains of effects — calculate derived state and update in one event handler

Refs

  • Use for values that don't affect rendering (timer IDs, DOM node references)
  • Never read or write ref.current during render; only in event handlers and effects
  • Use ref callbacks (not useRef in loops) for dynamic lists
  • Use useImperativeHandle to limit what parent can access

Custom Hooks

  • Share logic, not state — each call gets an independent state instance
  • Name useXxx only if it actually calls other hooks; otherwise use a regular function
  • Avoid lifecycle hooks (useMount, useEffectOnce) — use useEffect directly so the linter catches missing deps
  • Keep focused on a single concrete use case

Component Patterns

  • Controlled: parent owns state; uncontrolled: component owns state
  • Prefer composition with children over prop drilling
  • Treat boolean props that switch large component trees (isEditing, isThread, hideAttachments) as a composition smell; prefer separate composed components for distinct use cases
  • For complex reusable UI, prefer compound components with provider-scoped state/actions over monolithic components with many optional props
  • Use Context for scoped component families as well as truly global state, when it defines a local interface consumed by descendants
  • Render JSX directly for UI variation; avoid config-array mini-frameworks unless the config is real domain data
  • Lift the provider boundary when sibling or external controls need access to the same state/actions
  • Use flushSync when you need to read the DOM synchronously after a state update

See react-patterns.md for code examples and detailed patterns.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts3mo3 checks · Risk SAFE
  • Gen Agent Trust Hub3mo

    This skill provides architectural guidelines and code examples for React development best practices. No malicious behavior, prompt injections, or security risks were identified.

  • Socket3mo

    No alerts

  • Snyk3mo

    Risk: LOW · No issues

Signed by skilld at 2921eb8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 7 months ago
  • React
  • TypeScript
  • hooks
  • effects
  • refs
  • custom-hooks
  • component-patterns
  • state-management

README badge

README badge for alleneubank/claude-code

Provides a decision tree for choosing between event handlers, computed values, useMemo, key prop, Effects, useEffectEvent, and refs in React components. Emphasizes treating Effects as escape hatches for external system synchronization only, and covers custom hooks, component composition patterns, and Context usage for TypeScript-based React projects.

Generated from the current SKILL.md.

Should I use useEffect for derived state or computed values?
No. Calculate derived state during render instead. useEffect is for synchronizing with external systems like WebSocket or browser APIs, not for computing values from props or state.
When should I use a ref instead of state?
Use refs for values that don't affect rendering, such as timer IDs or DOM node references. Never read or write ref.current during render — only in event handlers and effects.
How do I reset component state when a prop changes?
Use the `key` prop to remount the component, rather than using an effect. This is simpler and avoids the pitfall of managing dependencies.
Should I create custom hooks for all reusable logic?
Only name a function `useXxx` if it actually calls other hooks. For non-hook logic, use a regular function. Avoid lifecycle-style hooks like `useMount` — use `useEffect` directly so the linter catches missing dependencies.
Does this skill cover TypeScript patterns with React?
Yes. Load this skill alongside `typescript-best-practices`. TypeScript patterns like type-first development, discriminated unions, and Zod validation apply directly to React code.

Generated from the current SKILL.md. These answers refresh after source changes.