Skip to main content
skill CX Codex

react-patterns · jezweb — Claude Code skill: React 19 patterns

A skill that checks React 19 components for waterfalls, bundle bloat and re-renders, and suggests composition fixes. Useful while writing or reviewing code.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add jezweb/claude-skills --skill react-patterns -a claude-code
Open on GitHub

What react-patterns does

The skill ships a rule set for React 19, ranked by impact. Critical sections come first: killing waterfalls from sequential await calls and trimming bundle size. Then composition architecture, re-render prevention and React 19 specifics.

Everything is laid out as problem-to-fix tables. Two independent awaits become one Promise.all; barrel imports become direct file imports; heavy components move behind React.lazy() and <Suspense>. The React 19 block covers useActionState replacing useFormState, ref as a plain prop, use(MyContext) in place of useContext, and the useOptimistic hook.

The skill only reads. Its allowed-tools list is Read, Glob and Grep, so it will point at problems rather than edit files. The source text cuts off inside the rendering performance section, so the full rule list isn't visible there. It targets Vite and Cloudflare Workers projects — on a different bundler, expect to verify the bundle advice yourself.

What it helps with

  • spot sequential await calls in components and run them in parallel
  • shrink the bundle by dropping barrel imports and heavy libraries from first load
  • split a component with a pile of boolean props into explicit variants
  • stop re-renders caused by objects in useEffect dependencies
  • move code onto React 19 APIs: useActionState, ref as a prop, use()

Example prompts for the agent

  • run react-patterns over src/components and list the critical issues
  • why is this list slow? check it with react-patterns and find the waterfalls
  • refactor Dialog.tsx using the composition patterns from react-patterns

How to install react-patterns

1Skills CLI (Vercel)

npx skills add jezweb/claude-skills --skill react-patterns -a claude-code

2Manually: put the files in place

~/.claude/skills/react-patterns/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/react-patterns/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about react-patterns

How do I install react-patterns in Claude?

Run npx skills add jezweb/claude-skills --skill react-patterns -a claude-code. The skill lands in ~/.claude/skills/react-patterns/SKILL.md.

What does react-patterns do?

It gives the agent a React 19 checklist: waterfalls, bundle size, component composition and re-renders. The agent applies it while writing, reviewing or refactoring components.

Which tools can the skill use?

Read, Glob and Grep only. It won't change your code, so you or a separate command have to apply what it finds.

Source text

SKILL.md · MIT
---
name: react-patterns
description: "React 19 performance patterns and composition architecture for Vite + Cloudflare projects. 50+ rules ranked by impact — eliminating waterfalls, bundle optimisation, re-render prevention, composition over boolean props, server/client boundaries, and React 19 APIs. Use when writing, reviewing, or refactoring React components. Triggers: 'react patterns', 'react review', 'react performance', 'optimise components', 'react best practices', 'composition patterns', 'why is it slow', 'reduce re-renders', 'fix waterfall'."
compatibility: claude-code-only
allowed-tools:
  - Read
  - Glob
  - Grep
---

# React Patterns

Performance and composition patterns for React 19 + Vite + Cloudflare Workers projects. Use as a checklist when writing new components, a review guide when auditing existing code, or a refactoring playbook when something feels slow or tangled.

Rules are ranked by impact. Fix CRITICAL issues before touching MEDIUM ones.

## When to Apply

- Writing new React components or pages
- Reviewing code for performance issues
- Refactoring components with too many props or re-renders
- Debugging "why is this slow?" or "why does this re-render?"
- Building reusable component libraries
- Code review before merging

## 1. Eliminating Waterfalls (CRITICAL)

Sequential async calls where they could be parallel. The #1 performance killer.

| Pattern | Problem | Fix |
|---------|---------|-----|
| **Await in sequence** | `const a = await getA(); const b = await getB();` | `const [a, b] = await Promise.all([getA(), getB()]);` |
| **Fetch in child** | Parent renders, then child fetches, then grandchild fetches | Hoist fetches to the highest common ancestor, pass data down |
| **Suspense cascade** | Multiple Suspense boundaries that resolve sequentially | One Suspense boundary wrapping all async siblings |
| **Await before branch** | `const data = await fetch(); if (condition) { use(data); }` | Move await inside the branch — don't fetch what you might not use |
| **Import then render** | `const Component = await import('./Heavy'); return <Component />` | Use `React.lazy()` + `<Suspense>` — renders fallback instantly |

**How to find them**: Search for `await` in components. Each `await` is a potential waterfall. If two awaits are independent, they should be parallel.

## 2. Bundle Size (CRITICAL)

Every KB the user downloads is a KB they wait for.

| Pattern | Problem | Fix |
|---------|---------|-----|
| **Barrel imports** | `import { Button } from '@/components'` pulls the entire barrel file | `import { Button } from '@/components/ui/button'` — direct import |
| **No code splitting** | Heavy component loaded on every page | `React.lazy(() => import('./HeavyComponent'))` + `<Suspense>` |
| **Third-party at load** | Analytics/tracking loaded before the app renders | Load after hydration: `useEffect(() => { import('./analytics') }, [])` |
| **Full library import** | `import _ from 'lodash'` (70KB) | `import debounce from 'lodash/debounce'` (1KB) |
| **Lucide tree-shaking** | `import * as Icons from 'lucide-react'` (all icons) | Explicit map: `import { Home, Settings } from 'lucide-react'` |
| **Duplicate React** | Library bundles its own React → "Cannot read properties of null" | `resolve.dedupe: ['react', 'react-dom']` in vite.config.ts |

**How to find them**: `npx vite-bundle-visualizer` — shows what's in your bundle.

## 3. Composition Architecture (HIGH)

How you structure components matters more than how you optimise them.

| Pattern | Problem | Fix |
|---------|---------|-----|
| **Boolean prop explosion** | `<Card isCompact isClickable showBorder hasIcon isLoading>` | Explicit variants: `<CompactCard>`, `<ClickableCard>` |
| **Compound components** | Complex component with 15 props | Split into `<Dialog>`, `<Dialog.Trigger>`, `<Dialog.Content>` with shared context |
| **renderX props** | `<Layout renderSidebar={...} renderHeader={...} renderFooter={...}>` | Use children + named slots: `<Layout><Sidebar /><Header /></Layout>` |
| **Lift state** | Sibling components can't share state | Move state to parent or context provider |
| **Provider implementation** | Consumer code knows about state management internals | Provider exposes interface `{ state, actions, meta }` — implementation hidden |
| **Inline components** | `function Parent() { function Child() { ... } return <Child /> }` | Define Child outside Parent — inline components remount on every render |

**The test**: If a component has more than 5 boolean props, it needs composition, not more props.

## 4. Re-render Prevention (MEDIUM)

Not all re-renders are bad. Only fix re-renders that cause visible jank or wasted computation.

| Pattern | Problem | Fix |
|---------|---------|-----|
| **Default object/array props** | `function Foo({ items = [] })` → new array ref every render | Hoist: `const DEFAULT = []; function Foo({ items = DEFAULT })` |
| **Derived state in effect** | `useEffect(() => setFiltered(items.filter(...)), [items])` | Derive during render: `const filtered = useMemo(() => items.filter(...), [items])` |
| **Object dependency** | `useEffect(() => {...}, [config])` fires every render if config is `{}` | Use primitive deps: `useEffect(() => {...}, [config.id, config.type])` |
| **Subscribe to unused state** | Component reads `{ user, theme, settings }` but only uses `user` | Split context or use selector: `useSyncExternalStore` |
| **State for transient values** | `const [mouseX, setMouseX] = useState(0)` on mousemove | Use `useRef` for values that change frequently but don't need re-render |
| **Inline callback props** | `<Button onClick={() => doThing(id)} />` — new function every render | `useCallback` or functional setState: `<Button onClick={handleClick} />` |

**How to find them**: React DevTools Profiler → "Why did this render?" or `<React.StrictMode>` double-renders in dev.

## 5. React 19 Specifics (MEDIUM)

Patterns that changed or are new in React 19.

| Pattern | Old (React 18) | New (React 19) |
|---------|---------------|----------------|
| **Form state** | `useFormState` | `useActionState` — renamed |
| **Ref forwarding** | `forwardRef((props, ref) => ...)` | `function Component({ ref, ...props })` — ref is a regular prop |
| **Context** | `useContext(MyContext)` | `use(MyContext)` — works in conditionals and loops |
| **Pending UI** | Manual loading state | `useTransition` + `startTransition` for non-urgent updates |
| **Route-level lazy** | Works with `createBrowserRouter` only | Still true — `<Route lazy={...}>` is silently ignored with `<BrowserRouter>` |
| **Optimistic updates** | Manual state management | `useOptimistic` hook |
| **Metadata** | Helmet or manual `<head>` management | `<title>`, `<meta>`, `<link>` in component JSX — hoisted to `<head>` automatically |

## 6. Rendering Performance (MEDIUM)

| Pattern | Problem | Fix |
|---------|---------|-----|
| **Layout shift on load** | Content jumps when async data arrives | Skeleton screens matching final layout dimensions |
| **Animate SVG directly** | Janky SVG animation | Wrap in `<div>`, animate the div instead |
| **Large list rendering** | 1000+ items in a table/list | `@tanstack/react-virtual` for virtualised rendering |
| **content-visibility** | Long scrollable content renders everything upfront | `content-visibility: auto` on off-screen sections |
| **Conditional render with &&** | `{count && <Items />}` renders `0` when count is 0 | Use ternary: `{count > 0 ? <Items /> : null}` |

## 7. Data Fetching (MEDIUM)

| Pattern | Problem | Fix |
|---------|---------|-----|
| **No deduplication** | Same data fetched by 3 components | TanStack Query or SWR — automatic dedup + caching |
| **Fetch on mount** | `useEffect(() => { fetch(...) }, [])` — waterfalls, no caching, no dedup | TanStack Query: `useQuery({ queryKey: ['users'], queryFn: fetchUsers })` |
| **No optimistic update** | User clicks save, waits 2 seconds, then sees change | `useMutation` with `onMutate` for instant visual feedback |
| **Stale closure in interval** | `setInterval` captures stale state | `useRef` for the interval ID and current values |
| **Polling without cleanup** | `setInterval` in useEffect without `clearInterval` | Return cleanup: `useEffect(() => { const id = setInterval(...); return () => clearInterval(id); })` |

## 8. Vite + Cloudflare Specifics (MEDIUM)

| Pattern | Problem | Fix |
|---------|---------|-----|
| **`import.meta.env` in Node scripts** | Undefined — only works in Vite-processed files | Use `loadEnv()` from vite |
| **React duplicate instance** | Library bundles its own React | `resolve.dedupe` + `optimizeDeps.include` in vite.config.ts |
| **Radix Select empty string** | `<SelectItem value="">` throws | Use sentinel: `<SelectItem value="__any__">` |
| **React Hook Form null** | `{...field}` passes null to Input | Spread manually: `value={field.value ?? ''}` |
| **Env vars at edge** | `process.env` doesn't exist in Workers | Use `c.env` (Hono context) or `import.meta.env` (Vite build-time) |

## Using as a Review Checklist

When reviewing code, go through categories 1-3 (CRITICAL + HIGH) for every PR. Categories 4-8 only when performance is a concern.

```
/react-patterns [file or component path]
```

Read the file, check against rules in priority order, report findings as:
```
file:line — [rule] description of issue
```

© jezweb · MIT · jezweb/claude-skills

Similar skills

Everything for Frontend and UI →

react-patterns by other authors comes first.

react-patterns affaan-m A skill for Claude and other AI editors that steers the agent toward idiomatic React 18/19: hooks discipline, server/client boundaries, forms, data fetching. CX Codex +1 4,900installs react-patterns giuseppe-trisciuoglio Teaches your agent React 19 and Next.js App Router patterns: Server Components, Server Actions, useOptimistic, Suspense boundaries. Useful when the app is already on React 19. CX Codex +1 4,800installs react-patterns manutej A skill that hands your agent ready React recipes: hooks, component composition, state management and fewer wasted re-renders. CX Codex +1 471installs clerk-react-patterns clerk Provides authentication patterns for React single-page apps using @clerk/react in Vite and CRA. It helps implement route guards, session hooks, and custom forms. CX Codex +1 19,700installs react-dev softaworks Provides type-safe React 18 and 19 patterns for TypeScript components, hooks, and Server Actions. CX Codex +1 4,100installs react-vite-best-practices agent-skills A skill with 23 rules for optimizing React apps built with Vite: build config, code splitting, HMR, assets, env variables and bundle analysis. Useful when an agent writes or reviews components. CX Codex +1 2,900installs react pproenca A skill with 49 React 19 rules and a codebase review algorithm. Useful when writing components, migrating from React 18, or auditing a repo. CX Codex +1 489installs react19-concurrent-patterns official github Preserves React 18 concurrent patterns during React 19 migrations and guides the adoption of use(), useOptimistic, and Actions. 1,100installs react-composition-2026 patterns.dev A skill that pushes your agent away from boolean props and rigid component APIs toward compound components, explicit variants and children. CX Codex +1 1,100installs

From the same set60

social-media-posts Creates posts for LinkedIn, Facebook, Instagram and Reddit in each platform’s format. Use it for a new announcement, existing content or a coordinated campaign. CX Codex +1 1,400installs mcp-builder A skill that takes a short brief and turns it into a deployable MCP server on Python with FastMCP, complete with local tests and a pre-deploy checklist. CX Codex +1 1,400installs cloudflare-worker-builder Scaffolds Cloudflare Worker projects with Hono routing, Vite dev server, and Static Assets. It configures D1, R2, and KV bindings and fixes deployment routing conflicts. CX Codex +1 1,400installs design-review Reviews the visual quality of a web page or app and produces a findings report with screenshots. Use it when an interface looks off and the cause is hard to spot. CX Codex +1 1,400installs react-native Performance guidelines and architecture patterns for React Native and Expo apps. Helps coding agents handle list virtualization, UI-thread animations, and navigation. CX Codex +1 1,300installs github-release Prepares a GitHub release by checking code for public publishing, creating a tag, and publishing through gh. Use it before making a repository public. CX Codex +1 1,300installs d1-migration Walks Cloudflare D1 migrations through Drizzle: generate the SQL, read it for traps, apply to local and remote, unstick partial runs. CX Codex +1 1,200installs deep-research Does the digging before you write code: scans your own projects, rivals, forums and libraries, then hands back a research brief. CX Codex +1 1,200installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor