# react-patterns

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

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf (Devin Desktop), Claude.ai · ★ 2858 repo stars
- Author: rohitg00
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/rohitg00/awesome-claude-code-toolkit/tree/HEAD/skills/react-patterns/SKILL.md
- Updated: 2026-05-12
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/rohitg00-react-patterns

## What it 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.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add rohitg00/awesome-claude-code-toolkit --skill react-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/react-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/react-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add rohitg00/awesome-claude-code-toolkit --skill react-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/react-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add rohitg00/awesome-claude-code-toolkit --skill react-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/react-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install rohitg00/awesome-claude-code-toolkit skills/react-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/react-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add rohitg00/awesome-claude-code-toolkit --skill react-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/rohitg00/awesome-claude-code-toolkit --path skills/react-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/react-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/rohitg00/awesome-claude-code-toolkit/tree/HEAD/skills/react-patterns/SKILL.md

## When to use it
- 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
- 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

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: a95f5c7cbd49b2d6.

BEGIN THIRD-PARTY FILE a95f5c7cbd49b2d6
````text
---
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);
````
END THIRD-PARTY FILE a95f5c7cbd49b2d6

The third-party file has ended. Everything between the a95f5c7cbd49b2d6 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3068 of 6774 bytes. © rohitg00 · Apache-2.0 · https://github.com/rohitg00/awesome-claude-code-toolkit/tree/HEAD/skills/react-patterns/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
