Jeffallan/claude-skills / skills/react-expert
react-expert
VerifiedUse when building React 18+ applications in .jsx or .tsx files, Next.js App Router projects, or create-react-app setups. Creates components, implements custom hooks, debugs rendering issues, migrates class components to functional, and implements state management. Invoke for Server Components, Suspense boundaries, useActionState forms, performance optimization, or React 19 features.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.3 KB |
| references/hooks-patterns.md | markdown | 3.6 KB |
| references/migration-class-to-modern.md | markdown | 23.5 KB |
| references/performance.md | markdown | 3.9 KB |
| references/react-19-features.md | markdown | 3.8 KB |
| references/server-components.md | markdown | 3.1 KB |
| references/state-management.md | markdown | 4.0 KB |
| references/testing-react.md | markdown | 3.9 KB |
references/react-19-features.md
View on GitHub# React 19 Features
## use() Hook
```tsx
import { use, Suspense } from 'react';
// Read promises in render
function Comments({ commentsPromise }: { commentsPromise: Promise<Comment[]> }) {
const comments = use(commentsPromise);
return (
<ul>
{comments.map(c => <li key={c.id}>{c.text}</li>)}
</ul>
);
}
// Parent creates promise, child reads it
function Post({ postId }: { postId: string }) {
const commentsPromise = fetchComments(postId);
return (
<article>
<PostContent id={postId} />
<Suspense fallback={<CommentsSkeleton />}>
<Comments commentsPromise={commentsPromise} />
</Suspense>
</article>
);
}
// Read context conditionally
function Theme({ children }: { children: React.ReactNode }) {
if (someCondition) {
const theme = use(ThemeContext);
return <div className={theme}>{children}</div>;
}
return children;
}
```
## useActionState
```tsx
'use client';
import { useActionState } from 'react';
interface FormState {
error?: string;
success?: boolean;
}
async function submitAction(prevState: FormState, formData: FormData): Promise<FormState> {
'use server';
const email = formData.get('email') as string;
try {
await subscribe(email);
return { success: true };
} catch {
return { error: 'Failed to subscribe' };
}
}
function NewsletterForm() {
const [state, formAction, isPending] = useActionState(submitAction, {});
return (
<form action={formAction}>
<input name="email" type="email" required disabled={isPending} />
<button type="submit" disabled={isPending}>
{isPending ? 'Subscribing...' : 'Subscribe'}
</button>
{state.error && <p className="error">{state.error}</p>}
{state.success && <p className="success">Subscribed!</p>}
</form>
);
}
```
## useFormStatus
```tsx
'use client';
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending, data, method, action } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Submitting...' : 'Submit'}
</button>
);
}
// Must be used inside a <form>
function ContactForm() {
return (
<form action={submitAction}>
<input name="message" />
<SubmitButton />
</form>
);
}
```
## useOptimistic
```tsx
'use client';
import { useOptimistic } from 'react';
function TodoList({ todos }: { todos: Todo[] }) {
const [optimisticTodos, addOptimisticTodo] = useOptimistic(
todos,
(state, newTodo: Todo) => [...state, newTodo]
);
async function addTodo(formData: FormData) {
const text = formData.get('text') as string;
// Immediately update UI
addOptimisticTodo({ id: 'temp', text, completed: false });
// Then persist
await createTodo(text);
}
return (
<>
<ul>
{optimisticTodos.map(todo => (
<li key={todo.id}>{todo.text}</li>
))}
</ul>
<form action={addTodo}>
<input name="text" />
<button>Add</button>
</form>
</>
);
}
```
## ref as Prop (No forwardRef)
```tsx
// React 19: ref is just a prop
function Input({ ref, ...props }: { ref?: React.Ref<HTMLInputElement> }) {
return <input ref={ref} {...props} />;
}
// No need for forwardRef anymore
function Form() {
const inputRef = useRef<HTMLInputElement>(null);
return <Input ref={inputRef} placeholder="Enter text" />;
}
```
## Quick Reference
| Hook | Purpose |
|------|---------|
| `use()` | Read promise/context in render |
| `useActionState()` | Form action state + pending |
| `useFormStatus()` | Form pending state (child) |
| `useOptimistic()` | Optimistic UI updates |
| Pattern | When |
|---------|------|
| `use(promise)` | Suspense data fetching |
| `use(context)` | Conditional context read |
| `useActionState` | Server Actions with state |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |