const value = use(resource);
// resource can be a Promise or a Context
example
import { use, Suspense } from'react';
function UserGreeting({ userPromise }) {
// React suspends until the promise resolvesconst user = use(userPromise);
return <h2>Hello, {user.name}!</h2>;
}
function App() {
const userPromise = fetchCurrentUser();
return (
<Suspense fallback={<p>Loading user...</p>}>
<UserGreeting userPromise={userPromise} />
</Suspense>
);
}
Note Unlike other hooks, use() can be called inside if statements and loops. When reading a promise, wrap the component in Suspense. The promise should be created outside the component or cached -- do not create new promises inside render.
use hookread promisesuspense datareact 19 useasync component
use() with Context
syntax
const value = use(SomeContext);
// Can be called conditionally, unlike useContext
Note use(Context) works like useContext but can be placed after early returns or inside conditionals. This is useful when you only need the context value in some code paths.
use context conditionalconditional contextuse vs useContextread context conditionally
Note Actions are async functions passed to the action prop of <form>. They receive FormData as an argument. React handles the pending state and error transitions automatically. Actions work with useActionState and useFormStatus for richer patterns.
form actionactionsasync form submitformDatareact 19 actions
Note useFormStatus must be called from a component rendered inside a <form>. It will not work if called in the same component that renders the form -- it reads from the nearest parent form. Import it from 'react-dom', not 'react'.
useFormStatusform pendingsubmit button loadingform submission statedisable while submitting
Note useOptimistic shows a temporary state while an async action is in progress. When the action completes (or fails), React reverts to the actual state. The optimistic value is automatically rolled back if the action throws.
useOptimisticoptimistic updateinstant ui feedbackoptimistic statetemporary state
Note useActionState combines action handling with state management. The action function receives the previous state as its first argument and FormData as its second. The third return value (isPending) tells you if the action is running.
useActionStateform state actionaction with stateform error handlingserver action state
Note React 19 passes ref as a regular prop to function components. forwardRef is deprecated -- migrate by moving ref into the props destructuring. Existing forwardRef code continues to work but will show deprecation warnings.
ref as propno forwardRefreact 19 refpass refdeprecate forwardRef
function ProductPage({ product }) {
return (
<article>
<title>{product.name} | ShopApp</title>
<meta name="description" content={product.summary} />
<link rel="canonical" href={`/products/${product.slug}`} />
<h1>{product.name}</h1>
<p>{product.description}</p>
<strong>${product.price}</strong>
</article>
);
}
// React hoists these tags into the <head> automatically
Note In React 19, metadata tags rendered inside components are automatically hoisted into the document <head>. This eliminates the need for third-party helmet libraries for basic metadata management. Works with SSR and client rendering.
document titlemeta tagshead metadataseo reactpage titlereact helmet alternative