React 19
Overview of New Features
| Feature |
Description |
| Actions |
Async functions in transitions for data mutations |
useActionState |
Handle action state with pending/error |
useFormStatus |
Access parent form status |
useOptimistic |
Optimistic UI updates |
use() |
Read resources in render (Promises, Context) |
| Server Components |
Components that render on server |
| Server Actions |
Server functions called from client |
| React Compiler |
Automatic memoization |
| Ref as prop |
Pass ref directly without forwardRef |
Actions
Actions are async functions used in transitions to handle mutations:
import { useTransition } from 'react';
function UpdateProfile() {
const [isPending, startTransition] = useTransition();
async function handleSubmit(formData: FormData) {
startTransition(async () => {
const result = await updateProfile(formData);
if (result.error) {
showToast(result.error);
}
});
}
return (
<form action={handleSubmit}>
<input name="name" type="text" />
<button type="submit" disabled={isPending}>
{isPending ? 'Saving...' : 'Save'}
</button>
</form>
);
}
useActionState
Replaces the experimental useFormState. Manages form action state including pending status:
import { useActionState } from 'react';
interface FormState {
message: string | null;
errors: Record<string, string[]>;
}
async function createPost(prevState: FormState, formData: FormData): Promise<FormState> {
const title = formData.get('title') as string;
if (!title || title.length < 3) {
return { message: null, errors: { title: ['Title must be at least 3 characters'] } };
}
try {
await savePost({ title });
return { message: 'Post created!', errors: {} };
} catch (error) {
return { message: 'Failed to create post', errors: {} };
}
}
function CreatePostForm() {
const [state, formAction, isPending] = useActionState(createPost, {
message: null,
errors: {}
});
return (
<form action={formAction}>
<input name="title" type="text" />
{state.errors.title && <p className="error">{state.errors.title[0]}</p>}
<button type="submit" disabled={isPending}>
{isPending ? 'Creating...' : 'Create Post'}
</button>
</form>
);
}
useFormStatus
Access the status of a parent <form> from any child component:
import { useFormStatus } from 'react-dom';
function SubmitButton() {
const { pending, data, method, action } = useFormStatus();
return (
<button type="submit" disabled={pending}>
{pending ? 'Submitting...' : 'Submit'}
</button>
);
}
// Usage - must be child of <form>
function ContactForm() {
return (
<form action={submitContact}>
<input name="email" type="email" required />
<SubmitButton />
</form>
);
}
Reusable Form Components
'use client';
import { useFormStatus } from 'react-dom';
export function FormButton({ children, pendingText = 'Submitting...', ...props }) {
const { pending } = useFormStatus();
return (
<button {...props} disabled={pending || props.disabled}>
{pending ? pendingText : children}
</button>
);
}
Full Reference: See hooks.md for useOptimistic, use() hook, Ref handling, Document Metadata.
Server Components & Server Actions
// app/users/page.tsx (Server Component by default)
export default async function UsersPage() {
const users = await fetchUsers();
return <UserList users={users} />;
}
// app/actions.ts
'use server';
export async function createPost(formData: FormData) {
const title = formData.get('title') as string;
await db.post.create({ data: { title } });
revalidatePath('/posts');
redirect(`/posts`);
}
Full Reference: See server.md for Server Components patterns, React Compiler, Migration Guide.
Best Practices
- ✅ Use Actions for form submissions and mutations
- ✅ Use
useOptimistic for immediate feedback
- ✅ Use
use() instead of useEffect for data fetching
- ✅ Let React Compiler handle memoization
- ✅ Use Server Components for static content
- ✅ Use Server Actions for secure mutations
- ❌ Don't create Promises inside components for
use()
- ❌ Don't mix client/server code without proper boundaries
When NOT to Use This Skill
- React 18 and earlier features - Use
react skill instead
- General form handling - Use
react-forms or react-hook-form skills
- Performance optimization - Use
react-performance skill
Anti-Patterns
| Anti-Pattern |
Problem |
Solution |
| Creating Promises in render for use() |
New promise every render |
Create promise outside component |
| Using useFormState instead of useActionState |
Deprecated in React 19 |
Use useActionState with isPending |
| Missing 'use server' directive |
Code runs on client |
Add 'use server' at top of file |
| Not validating Server Action inputs |
Security vulnerability |
Always validate with Zod |
Quick Troubleshooting
| Issue |
Likely Cause |
Fix |
| Action not working |
Missing action attribute |
Add action={serverAction} to form |
| isPending not available |
Using old useFormState |
Switch to useActionState |
| Serialization errors |
Passing functions/classes |
Only pass serializable data |
| ref not working |
Using old forwardRef pattern |
Pass ref as regular prop |
Reference Files
| File |
Content |
| hooks.md |
useOptimistic, use(), Ref handling, Metadata |
| server.md |
Server Components, Server Actions, Compiler, Migration |
External Documentation
1---2name: react-193description: |4 React 19 new features and APIs. Covers Actions, useActionState, useFormStatus,5 useOptimistic, use() hook, Server Components, Server Actions, improved ref handling,6 document metadata, and new compiler.78 USE WHEN: user mentions "React 19", "useActionState", "useFormStatus", "useOptimistic",9 "use() hook", "Server Components", "Server Actions", "React Compiler", asks about10 "React 19 features", "Actions in React", "ref as prop"1112 DO NOT USE FOR: React 18 and earlier - use `react` skill instead,13 forms in general - use `react-forms` or `react-hook-form` skills instead14allowed-tools: Read, Grep, Glob, Write, Edit15metadata:16 source: https://skillmd.com/skills/claude-dev-suite/react-1917---1819# React 192021## Overview of New Features2223| Feature | Description |24|---------|-------------|25| Actions | Async functions in transitions for data mutations |26| `useActionState` | Handle action state with pending/error |27| `useFormStatus` | Access parent form status |28| `useOptimistic` | Optimistic UI updates |29| `use()` | Read resources in render (Promises, Context) |30| Server Components | Components that render on server |31| Server Actions | Server functions called from client |32| React Compiler | Automatic memoization |33| Ref as prop | Pass ref directly without forwardRef |3435---3637## Actions3839Actions are async functions used in transitions to handle mutations:4041```tsx42import { useTransition } from 'react';4344function UpdateProfile() {45 const [isPending, startTransition] = useTransition();4647 async function handleSubmit(formData: FormData) {48 startTransition(async () => {49 const result = await updateProfile(formData);50 if (result.error) {51 showToast(result.error);52 }53 });54 }5556 return (57 <form action={handleSubmit}>58 <input name="name" type="text" />59 <button type="submit" disabled={isPending}>60 {isPending ? 'Saving...' : 'Save'}61 </button>62 </form>63 );64}65```6667---6869## useActionState7071Replaces the experimental `useFormState`. Manages form action state including pending status:7273```tsx74import { useActionState } from 'react';7576interface FormState {77 message: string | null;78 errors: Record<string, string[]>;79}8081async function createPost(prevState: FormState, formData: FormData): Promise<FormState> {82 const title = formData.get('title') as string;8384 if (!title || title.length < 3) {85 return { message: null, errors: { title: ['Title must be at least 3 characters'] } };86 }8788 try {89 await savePost({ title });90 return { message: 'Post created!', errors: {} };91 } catch (error) {92 return { message: 'Failed to create post', errors: {} };93 }94}9596function CreatePostForm() {97 const [state, formAction, isPending] = useActionState(createPost, {98 message: null,99 errors: {}100 });101102 return (103 <form action={formAction}>104 <input name="title" type="text" />105 {state.errors.title && <p className="error">{state.errors.title[0]}</p>}106 <button type="submit" disabled={isPending}>107 {isPending ? 'Creating...' : 'Create Post'}108 </button>109 </form>110 );111}112```113114---115116## useFormStatus117118Access the status of a parent `<form>` from any child component:119120```tsx121import { useFormStatus } from 'react-dom';122123function SubmitButton() {124 const { pending, data, method, action } = useFormStatus();125126 return (127 <button type="submit" disabled={pending}>128 {pending ? 'Submitting...' : 'Submit'}129 </button>130 );131}132133// Usage - must be child of <form>134function ContactForm() {135 return (136 <form action={submitContact}>137 <input name="email" type="email" required />138 <SubmitButton />139 </form>140 );141}142```143144### Reusable Form Components145146```tsx147'use client';148import { useFormStatus } from 'react-dom';149150export function FormButton({ children, pendingText = 'Submitting...', ...props }) {151 const { pending } = useFormStatus();152153 return (154 <button {...props} disabled={pending || props.disabled}>155 {pending ? pendingText : children}156 </button>157 );158}159```160161> **Full Reference**: See [hooks.md](hooks.md) for useOptimistic, use() hook, Ref handling, Document Metadata.162163---164165## Server Components & Server Actions166167```tsx168// app/users/page.tsx (Server Component by default)169export default async function UsersPage() {170 const users = await fetchUsers();171 return <UserList users={users} />;172}173174// app/actions.ts175'use server';176export async function createPost(formData: FormData) {177 const title = formData.get('title') as string;178 await db.post.create({ data: { title } });179 revalidatePath('/posts');180 redirect(`/posts`);181}182```183184> **Full Reference**: See [server.md](server.md) for Server Components patterns, React Compiler, Migration Guide.185186---187188## Best Practices189190- ✅ Use Actions for form submissions and mutations191- ✅ Use `useOptimistic` for immediate feedback192- ✅ Use `use()` instead of useEffect for data fetching193- ✅ Let React Compiler handle memoization194- ✅ Use Server Components for static content195- ✅ Use Server Actions for secure mutations196- ❌ Don't create Promises inside components for `use()`197- ❌ Don't mix client/server code without proper boundaries198199---200201## When NOT to Use This Skill202203- **React 18 and earlier features** - Use `react` skill instead204- **General form handling** - Use `react-forms` or `react-hook-form` skills205- **Performance optimization** - Use `react-performance` skill206207---208209## Anti-Patterns210211| Anti-Pattern | Problem | Solution |212|--------------|---------|----------|213| Creating Promises in render for use() | New promise every render | Create promise outside component |214| Using useFormState instead of useActionState | Deprecated in React 19 | Use useActionState with isPending |215| Missing 'use server' directive | Code runs on client | Add 'use server' at top of file |216| Not validating Server Action inputs | Security vulnerability | Always validate with Zod |217218---219220## Quick Troubleshooting221222| Issue | Likely Cause | Fix |223|-------|--------------|-----|224| Action not working | Missing action attribute | Add action={serverAction} to form |225| isPending not available | Using old useFormState | Switch to useActionState |226| Serialization errors | Passing functions/classes | Only pass serializable data |227| ref not working | Using old forwardRef pattern | Pass ref as regular prop |228229---230231## Reference Files232233| File | Content |234|------|---------|235| [hooks.md](hooks.md) | useOptimistic, use(), Ref handling, Metadata |236| [server.md](server.md) | Server Components, Server Actions, Compiler, Migration |237238---239240## External Documentation241242- [React 19 Blog](https://react.dev/blog/2024/12/05/react-19)243- [React 19 Upgrade Guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide)