React 19 is a major release packed with new features, performance improvements, and important breaking changes. Here’s a comprehensive guide to what’s new, what’s changed, and how to upgrade smoothly.
startTransition now supports async functions (Actions), allowing you to perform async work (like fetches) inside transitions.useActionState is a new hook for managing state and pending status of actions.useOptimistic lets you optimistically update UI while a transition is in progress.import { startTransition, useActionState, useOptimistic } from 'react';
function MyForm() {
const [state, submitAction, isPending] = useActionState(async (prev, formData) => {
const result = await fetch('/api/submit', { method: 'POST', body: formData });
return await result.json();
}, {});
return (
<form action={submitAction}>
{/* form fields */}
<button type="submit" disabled={isPending}>Submit</button>
</form>
);
}
use APIuse API allows you to read promises or context directly in render.function UserProfile({ userPromise }) {
const user = use(userPromise);
return <div>{user.name}</div>;
}
forwardRef in many cases.<form action> and useFormStatus provide native support for form actions and status tracking.propTypes and defaultProps for functions removed: Use TypeScript or default parameters.ReactDOM.render, ReactDOM.hydrate, unmountComponentAtNode, findDOMNode removed: Use createRoot and hydrateRoot.npx types-react-codemod@latest preset-19 ./src to update deprecated types.useActionState, useOptimistic, use) for async and concurrent UI.import { useOptimistic, startTransition } from 'react';
function LikeButton({ postId }) {
const [likes, setLikes] = useOptimistic(0);
const handleLike = () => {
startTransition(() => {
setLikes(likes + 1); // Optimistically update
// Then send to server
fetch(`/api/like/${postId}`, { method: 'POST' });
});
};
return <button onClick={handleLike}>Like ({likes})</button>;
}
React 19 is a huge step forward for modern web apps. Upgrade today to take advantage of the latest features and performance improvements!