React 19 mit Claude Code: Neue Features & Migration 2026
React 19 ist das größte React-Release seit Hooks. Neue Hooks für asynchrone Operationen, stabile Server Components, verbesserte ref-Handhabung und Asset Loading — Claude Code kennt alle neuen APIs und hilft bei der Migration.
useActionState: Formulare ohne Redux
HookuseActionState — Der neue Formular-Standard NEU
# Prompt: "Erstelle ein Login-Formular mit useActionState und Server Actions"
// actions.ts (Server Action)
'use server';
export async function loginAction(prevState: any, formData: FormData) {
const email = formData.get('email') as string;
const password = formData.get('password') as string;
try {
await auth.signIn({ email, password });
return { success: true, error: null };
} catch (e) {
return { success: false, error: 'Ungültige Zugangsdaten' };
}
}
// LoginForm.tsx
'use client';
import { useActionState } from 'react'; // React 19!
import { loginAction } from './actions';
export function LoginForm() {
const [state, formAction, isPending] = useActionState(loginAction, {
success: false,
error: null,
});
return (
<form action={formAction}>
<input name="email" type="email" required />
<input name="password" type="password" required />
{state.error && <p className="error">{state.error}</p>}
<button disabled={isPending}>
{isPending ? 'Wird angemeldet...' : 'Anmelden'}
</button>
</form>
);
}
// Kein useState, kein onSubmit Handler, kein fetch — alles eingebaut!
React 19 Vorteil:
useActionState ersetzt das manuelle Pattern von useState + onSubmit + fetch + setLoading. Der isPending-State ist automatisch gesetzt während die Action läuft. Claude Code generiert dieses Pattern direkt auf Prompt.useOptimistic: Instant UI-Updates
HookuseOptimistic für pessimistisches UX NEU
# Prompt: "Todo-Liste mit optimistic Updates — UI sofort aktualisieren"
import { useOptimistic, useTransition } from 'react';
function TodoList({ todos }: { todos: Todo[] }) {
const [optimisticTodos, addOptimisticTodo] = useOptimistic(
todos,
(state: Todo[], newTodo: Todo) => [...state, newTodo]
);
const [isPending, startTransition] = useTransition();
async function handleAdd(text: string) {
const optimisticTodo = { id: 'temp', text, done: false };
startTransition(async () => {
addOptimisticTodo(optimisticTodo); // UI sofort aktualisieren
await saveTodo(text); // Server-Call im Hintergrund
// Bei Fehler: React rollt automatisch zurück!
});
}
return (
<ul>
{optimisticTodos.map(todo => (
<li key={todo.id} style={{ opacity: todo.id === 'temp' ? 0.6 : 1 }}>
{todo.text}
</li>
))}
</ul>
);
}
use(): Promises in Render lesen
Neuuse() Hook — Promise und Context direkt
# Prompt: "Lese einen Promise direkt im Component mit use()"
import { use, Suspense } from 'react';
// use() löst Promises auf — kein useEffect nötig!
function UserProfile({ userPromise }: { userPromise: Promise<User> }) {
const user = use(userPromise); // Suspense wird geworfen bis resolved
return <div>{user.name}</div>;
}
// Eltern-Component wrapped in Suspense:
function App() {
const userPromise = fetchUser(123); // Kein await!
return (
<Suspense fallback={<div>Lädt...</div>}>
<UserProfile userPromise={userPromise} />
</Suspense>
);
}
// use() kann auch Context lesen (bedingt — kein useContext-Limit!):
function ConditionalTheme({ show }: { show: boolean }) {
if (!show) return null;
const theme = use(ThemeContext); // ✅ In if-Block — mit use() erlaubt!
return <div style={{ color: theme.primary }}>Theme aktiv</div>;
}
use() vs. useEffect:
use() ist der deklarative Weg für async Daten im Render-Pfad. Kein useEffect + useState + setLoading mehr für einfaches Data Fetching — use() + Suspense übernimmt das komplett.ref als Prop: kein forwardRef mehr
Neuref als normaler Prop — forwardRef entfällt
# Vorher (React 18): forwardRef boilerplate
const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => {
return <input {...props} ref={ref} />;
});
# React 19: ref ist normaler Prop!
function Input({ ref, ...props }: InputProps & { ref?: React.Ref<HTMLInputElement> }) {
return <input {...props} ref={ref} />;
}
# Nutzung bleibt gleich:
const inputRef = useRef<HTMLInputElement>(null);
<Input ref={inputRef} placeholder="Text eingeben" />
Migration:
forwardRef ist in React 19 deprecated (nicht entfernt). Claude Code kann bestehende forwardRef-Komponenten automatisch auf den neuen ref-als-Prop-Stil migrieren — einfach Prompt: "Migriere alle forwardRef-Komponenten auf React 19 ref-Props".Asset Loading und Document Metadata
# Prompt: "React 19 Document Metadata direkt im Component"
// React 19: title, meta, link direkt im JSX — kein react-helmet mehr!
function BlogPost({ post }: { post: Post }) {
return (
<>
<title>{post.title} | Mein Blog</title>
<meta name="description" content={post.excerpt} />
<link rel="canonical" href={`https://example.com/blog/${post.slug}`} />
<article>
<h1>{post.title}</h1>
<p>{post.content}</p>
</article>
</>
);
}
// React hoisted title/meta automatisch in <head> — auch bei SSR!
// Stylesheet-Loading mit Priorität:
function Page() {
return (
<>
<link rel="stylesheet" href="/theme.css" precedence="default" />
<link rel="stylesheet" href="/component.css" precedence="high" />
// React lädt Stylesheets bevor Content gerendert wird
</>
);
}
Migration von React 18 auf 19
BreakingBreaking Changes beachten
# Prompt: "Prüfe mein Projekt auf React 19 Breaking Changes"
# Breaking Changes — Claude Code prüft diese automatisch:
# 1. ReactDOM.render() → createRoot() (schon seit React 18 deprecated)
# 2. string refs → useRef() (schon lange deprecated)
# 3. defaultProps auf Function Components entfernt (→ JS default params)
# 4. propTypes entfernt (→ TypeScript)
# 5. Legacy Context API (contextTypes/childContextTypes) entfernt
# 6. ReactDOM.findDOMNode() entfernt
# Migration-Script (codemod):
npx codemod@latest react/19/replace-reactdom-render
npx codemod@latest react/19/replace-string-ref
npx codemod@latest react/19/replace-act-import
npx codemod@latest react/19/replace-use-form-state
# Neue React 19 Dev Tools Warnung prüfen:
# "findDOMNode is deprecated" → sofort migrieren
Migration-Prompt für Claude Code: "Scanne mein gesamtes Projekt auf React 18 Deprecated APIs und migriere automatisch auf React 19. Zeige welche Dateien betroffen sind." Claude Code erstellt einen Migrations-Plan mit konkreten Datei-für-Datei Änderungen.
React 19 Modul im Kurs
Im Claude Code Mastery Kurs: vollständiges React 19 Modul mit allen neuen Hooks (useActionState, useOptimistic, use()), Server Components, Document Metadata und Migrations-Guide von React 18 — inkl. codemods und Breaking-Change-Checker.
14 Tage kostenlos testen →