Skip to content

skillFrontendreacttypescript

React Component Design

Designs and reviews React components for clean state, correct effects, composition and complete loading, empty and error states, in TypeScript.

npx workspacetemplates add react-component-design --tool claude-code

Writes 1 file to .claude/skills/react-component-design/

.claude/skills/react-component-design/SKILL.md28 lines · 1.7 KBFile
---
name: react-component-design
description: Designs and reviews React components for clean state, correct effects, composition and complete loading, empty and error states, in TypeScript.
---

# React component design

Write function components in TypeScript. Keep them small and boring.

## Steps

1. Define the job in one sentence. If it needs "and", split it into two components.
2. Type the props: required props first, no `any`, a discriminated union instead of several booleans (`status: 'idle' | 'loading' | 'error'`). Accept `children` or a slot prop instead of adding a prop per variation.
3. Place state at the lowest component that needs it. Do not store anything you can compute from props or other state; compute it during render (`useMemo` only after you measured).
4. Treat `useEffect` as a last resort. Never use it to transform data, reset state from props (use a `key`) or respond to a click (use the handler). Use it for subscriptions and syncing with outside systems, always with a cleanup and a complete dependency list. Fetch with the project's data library, not a bare effect.
5. Cover every data state: loading (skeleton or spinner), empty (a message and next action), error (readable text and retry), and success. Write them before the happy path.
6. Lists need stable `key` values from the data, never the index when order can change.
7. Prefer composition: pass components or render props instead of a config object that grows.
8. Make it accessible: native elements, labels, focus.

## Rules

- No prop drilling past two levels: use composition or context.
- Do not mutate props or state.

## Report

The component code, the states it handles, and anything you left to the caller.

What it does

React code gets hard to maintain in predictable ways: derived values stored in state, effects that fetch and sync, props lists that keep growing. This skill applies a short set of design rules to a component you are writing or reviewing.

It also insists that every component fed by data has an answer for loading, empty and error, because those are the states users see first and developers forget.

Example

you › Build a UserList component that loads users from /api/users

agent › Created UserList.tsx and UserRow.tsx. Props: onSelect(userId). State: one discriminated union for loading, error, empty and ready, no effect (uses the project query hook). Empty state links to "Invite a user", the error state has a Retry button. Rows are keyed by user.id. Search text is filtered during render, not stored.

Questions

Why so strict about useEffect?
Most effect bugs come from using it to move data around inside React. Computing during render or handling the event directly removes whole classes of stale-value bugs.
Does it work with Next.js or Vite?
Yes. The rules apply to any React 18 or newer project, and it follows the data-fetching library your repo already uses.
  • Bundle Size Reduction

    Skilljavascript

    Free