Skip to main content
skill CX Codex

react-patterns · rohitg00 — Claude Code skill: what it does, how to install

react-patterns is a Claude Code skill with React 19 patterns for Server Components, Server Actions, Suspense, and state management.

Apache-2.0 ★ 2,858 updated 2026-05-12

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

What react-patterns does

This skill supplies the agent with strict code patterns for React 19. It covers Server Components, server actions with cache revalidation, and isolated Suspense boundaries for data streaming. It also details state handling with useActionState, optimistic updates via useOptimistic, and compound component design.

The guidelines enforce pushing 'use client' down to leaf nodes so parent trees stay on the server. To avoid unneeded re-renders, the instructions explicitly forbid inline object and array declarations in JSX props.

What it helps with

  • handle asynchronous promises in render using the use() hook
  • implement form submissions with useActionState and Server Actions
  • create responsive like buttons using useOptimistic
  • build compound components like tabs using shared Context
  • isolate slow data requests behind individual Suspense fallbacks

Example prompts for the agent

  • Refactor this signup form using useActionState and a Server Action
  • Implement an optimistic like button with useOptimistic
  • Set up a Tabs component using the compound component pattern

How to install react-patterns

1Skills CLI (Vercel)

npx skills add rohitg00/awesome-claude-code-toolkit --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 to install react-patterns in Claude Code?

Run npx skills add rohitg00/awesome-claude-code-toolkit --skill react-patterns -a claude-code in your terminal or place the file into ~/.claude/skills/react-patterns/SKILL.md.

What does react-patterns do?

It guides Claude Code on modern React 19 best practices, including Server Components, Actions, custom hook architecture, and render optimization rules.

What requirement does the skill set for the use() hook?

While use() can run inside conditionals and loops, any component that unwraps a Promise with it must be wrapped in a <Suspense> boundary.

Source text

SKILL.md · Apache-2.0
---
name: react-patterns
description: React 19 patterns including Server Components, Actions, Suspense, hooks, and component composition
---

# React Patterns

## use() Hook (React 19)

`use()` reads values from Promises and Context directly in render. Unlike other hooks, it can be called inside conditionals and loops.

```tsx
import { use } from 'react';

function UserProfile({ userPromise }: { userPromise: Promise<User> }) {
  const user = use(userPromise);
  return <h1>{user.name}</h1>;
}

function ThemeButton() {
  const theme = use(ThemeContext);
  return <button style={{ background: theme.primary }}>Click</button>;
}
```

Wrap components that use `use()` with a Promise in a `<Suspense>` boundary.

## Server Components

```tsx
// app/users/page.tsx - Server Component (default, no directive needed)
import { UserList } from './UserList';

export default async function UsersPage() {
  const users = await fetch('https://api.example.com/users', {
    next: { revalidate: 60 },
  }).then(r => r.json());

  return <UserList users={users} />;
}

// app/users/UserList.tsx - Still a Server Component
export function UserList({ users }: { users: User[] }) {
  return (
    <ul>
      {users.map(u => (
        <li key={u.id}>
          {u.name}
          <DeleteButton userId={u.id} />
        </li>
      ))}
    </ul>
  );
}
```

Push `'use client'` as deep as possible. Only leaves that need interactivity should be Client Components.

## Server Actions

```tsx
// app/actions.ts
'use server';

import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';

export async function createPost(formData: FormData) {
  const title = formData.get('title') as string;
  const body = formData.get('body') as string;

  await db.insert(posts).values({ title, body });

  revalidatePath('/posts');
  redirect('/posts');
}
```

```tsx
// app/posts/new/page.tsx
import { createPost } from '../actions';

export default function NewPostPage() {
  return (
    <form action={createPost}>
      <input name="title" required />
      <textarea name="body" required />
      <button type="submit">Create</button>
    </form>
  );
}
```

## useActionState (React 19)

```tsx
'use client';

import { useActionState } from 'react';
import { createUser } from './actions';

function SignupForm() {
  const [state, formAction, isPending] = useActionState(createUser, {
    errors: {},
    message: '',
  });

  return (
    <form action={formAction}>
      <input name="email" />
      {state.errors.email && <p>{state.errors.email}</p>}
      <button disabled={isPending}>
        {isPending ? 'Creating...' : 'Sign Up'}
      </button>
      {state.message && <p>{state.message}</p>}
    </form>
  );
}
```

## useOptimistic (React 19)

```tsx
'use client';

import { useOptimistic } from 'react';
import { likePost } from './actions';

function LikeButton({ count, postId }: { count: number; postId: string }) {
  const [optimisticCount, addOptimistic] = useOptimistic(count);

  async function handleLike() {
    addOptimistic(prev => prev + 1);
    await likePost(postId);
  }

  return (
    <form action={handleLike}>
      <button type="submit">{optimisticCount} Likes</button>
    </form>
  );
}
```

## Suspense Boundaries

```tsx
import { Suspense } from 'react';

function Dashboard() {
  return (
    <div>
      <Suspense fallback={<StatsSkeleton />}>
        <StatsPanel />
      </Suspense>
      <div className="grid grid-cols-2">
        <Suspense fallback={<ChartSkeleton />}>
          <RevenueChart />
        </Suspense>
        <Suspense fallback={<ListSkeleton />}>
          <RecentActivity />
        </Suspense>
      </div>
    </div>
  );
}
```

Place Suspense boundaries around independent data-fetching units. Avoid wrapping the entire page in a single boundary (defeats the purpose of streaming).

## Error Boundaries

```tsx
'use client';

import { Component, type ReactNode } from 'react';

class ErrorBoundary extends Component<
  { fallback: ReactNode; children: ReactNode },
  { hasError: boolean }
> {
  state = { hasError: false };

  static getDerivedStateFromError() {
    return { hasError: true };
  }

  componentDidCatch(error: Error, info: React.ErrorInfo) {
    reportError(error, info.componentStack);
  }

  render() {
    if (this.state.hasError) return this.props.fallback;
    return this.props.children;
  }
}
```

Or use Next.js `error.tsx` convention for route-level error handling.

## Custom Hooks

```tsx
function useDebounce<T>(value: T, delay: number): T {
  const [debounced, setDebounced] = useState(value);

  useEffect(() => {
    const timer = setTimeout(() => setDebounced(value), delay);
    return () => clearTimeout(timer);
  }, [value, delay]);

  return debounced;
}

function useLocalStorage<T>(key: string, initial: T) {
  const [value, setValue] = useState<T>(() => {
    const stored = localStorage.getItem(key);
    return stored ? JSON.parse(stored) : initial;
  });

  useEffect(() => {
    localStorage.setItem(key, JSON.stringify(value));
  }, [key, value]);

  return [value, setValue] as const;
}
```

Rules for custom hooks:
- Prefix with `use`
- Extract when logic is shared between 2+ components
- Keep hooks focused on a single concern
- Return tuples `[value, setter]` or objects `{ data, error, loading }`

## Compound Components

```tsx
function Tabs({ children }: { children: ReactNode }) {
  const [active, setActive] = useState(0);
  return (
    <TabsContext value={{ active, setActive }}>
      <div role="tablist">{children}</div>
    </TabsContext>
  );
}

Tabs.Tab = function Tab({ index, children }: { index: number; children: ReactNode }) {
  const { active, setActive } = use(TabsContext);
  return (
    <button
      role="tab"
      aria-selected={active === index}
      onClick={() => setActive(index)}
    >
      {children}
    </button>
  );
};

Tabs.Panel = function Panel({ index, children }: { index: number; children: ReactNode }) {
  const { active } = use(TabsContext);
  if (active !== index) return null;
  return <div role="tabpanel">{children}</div>;
};

// Usage
<Tabs>
  <Tabs.Tab index={0}>Profile</Tabs.Tab>
  <Tabs.Tab index={1}>Settings</Tabs.Tab>
  <Tabs.Panel index={0}><ProfileForm /></Tabs.Panel>
  <Tabs.Panel index={1}><SettingsForm /></Tabs.Panel>
</Tabs>
```

## Performance Rules

- Avoid creating objects/arrays in JSX props (causes re-renders)
- Use `React.memo` only after profiling confirms unnecessary re-renders
- Prefer `useMemo`/`useCallback` for expensive computations or stable references passed to memoized children
- Use `key` to reset component state intentionally
- Colocate state: keep state as close to where it is used as possible
- Avoid prop drilling beyond 2 levels; use Context or composition instead

© rohitg00 · Apache-2.0 · rohitg00/awesome-claude-code-toolkit

Similar skills

All skills for Frontend and UI →

react-patterns by other authors comes first.

react-patterns affaan-m react-patterns — 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 6,700installs react-patterns jezweb react-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. CX Codex +1 1,300installs react-patterns giuseppe-trisciuoglio react-patterns 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 5,000installs react-patterns manutej A skill for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode that teaches the agent modern React patterns, from hooks and component composition to state management. Covers React 18+, Server Components, and memoization. CX Codex +1 474installs react-patterns oakoss react-patterns is a Claude Code skill that covers React 19 patterns, state choices, data loading with use(), and reducing needless re-renders when building or reviewing components. CX Codex +1 201installs react-expert https://github.com/Jeffallan react-expert — a skill for React 18+, Next.js App Router, and create-react-app work. It writes components and hooks, debugs rendering, and migrates class components to functions. CX Codex +1 5,900installs react-dev softaworks react-dev provides type-safe React 18 and 19 patterns for TypeScript components, hooks, and Server Actions. CX Codex +1 4,200installs react-nextjs-patterns duyet react-nextjs-patterns is a Claude Code skill that guides App Router and Server Component practices during Next.js development and code review, helping prevent data leaks and unnecessary memoization. CX Codex +1 1,100installs nextjs-use-search-params-suspense wsimmonds nextjs-use-search-params-suspense — a skill that shows how to read URL query parameters in Next.js client components: the 'use client' directive plus a Suspense wrapper. CX Codex +1 313installs react19-concurrent-patterns official github react19-concurrent-patterns preserves React 18 concurrent patterns during React 19 migrations and guides the adoption of use(), useOptimistic, and Actions. CX Codex +1 1,100installs react-data-fetching patterns.dev Teaches an agent modern React data fetching: caching, deduplication, optimistic updates, parallel loading. CX Codex +1 1,100installs

From the same set178

The whole set →
sales-engineer sales-engineer — a subagent that handles the technical side of selling: spins up demo environments, writes proof-of-concept code, builds integration guides, and runs competitive analysis. CX Codex ★ 2,858repo stars academic-researcher academic-researcher runs systematic literature reviews, inspects study methodology, and compiles evidence across papers. Built for technical and scientific research. CX Codex ★ 2,858repo stars devops-automation The devops-automation skill guides CI/CD design for GitHub Actions and configuration work with Docker, Kubernetes, Helm, and ArgoCD. Use it when planning an application build and deployment flow. CX Codex +1 ★ 2,858repo stars technology-scout technology-scout is a Claude Code subagent that evaluates emerging technologies, compares build-versus-buy options, and assesses vendors to inform adoption decisions. CX Codex ★ 2,858repo stars data-engineering The data-engineering skill offers patterns for ETL pipelines, data warehouses, and Apache Spark jobs. Use it to shape data quality checks and warehouse schemas. CX Codex +1 ★ 2,858repo stars python-best-practices python-best-practices guides Claude Code toward modern Python style: type hints, dataclasses, async code, project layout and pytest setup. CX Codex +1 ★ 2,858repo stars golang-idioms golang-idioms is a Claude Code skill that provides idiomatic Go guidance for error handling, concurrency, and testing. CX Codex +1 ★ 2,858repo stars workflow-optimizer The workflow-optimizer plugin analyzes development workflows and suggests ways to improve them. Use it when you want recommendations on how work in a project is organized. ★ 2,858repo stars

Project sponsors

Companies that keep this analytics open