Read supported resources with use
Read a stable Promise with use
React 19 introduced use for reading supported resources, including a Promise or context. When a Promise is unfinished, rendering the reader waits; when fulfilled, the reader gets its value; when rejected, React routes the failure to an Error Boundary. Unlike a standard Hook, use may appear in a loop or conditional within a component or custom Hook, but not inside try/catch. These client examples use controlled promises made outside render or in a user event, not real requests or a general data-fetching cache.
import React,{Suspense,use,useState,createContext,Component} from 'react';function controlledPromise(){ let resolve,reject; const promise=new Promise((yes,no)=>{resolve=yes;reject=no;}); // The fixture owns the promise; prevent unhandled rejection before mounting. promise.catch(()=>{}); return {promise,resolve,reject};}const first=controlledPromise();function Record({resource}){const name=use(resource);return <p>Record: {name}</p>;}export default function App(){return <section><button onClick={()=>first.resolve('Cedar specimen')}>Release record</button><Suspense fallback={<p role="status">Waiting for record</p>}><Record resource={first.promise}/></Suspense></section>;}Until the button is pressed, the pending resource keeps the reader behind the loading view. The button is outside that boundary so it remains available. When resolved, the name appears. Promise identity stays stable across retries. A new Promise on every render can repeatedly suspend and discard the work. Use a framework-supported resource mechanism in production; this module fixture contains only one synthetic record and is not safe for storing per-user server data.
Handle rejection and retry with a new resource
import React,{Suspense,use,useState,createContext,Component} from 'react';function controlledPromise(){ let resolve,reject; const promise=new Promise((yes,no)=>{resolve=yes;reject=no;}); // The fixture owns the promise; prevent unhandled rejection before mounting. promise.catch(()=>{}); return {promise,resolve,reject};}class Boundary extends Component { state={failed:false}; static getDerivedStateFromError(){return {failed:true};} render(){return this.state.failed?<p role="alert">Record unavailable.</p>:this.props.children;}}const first=controlledPromise();function Record({promise}){return <p>{use(promise)}</p>;}export default function App(){const [job,setJob]=useState({id:0,resource:first}); function retry(){setJob({id:job.id+1,resource:controlledPromise()});} return <section><button onClick={()=>job.resource.resolve('Cedar record ready')}>Resolve</button><button onClick={()=>job.resource.reject(new Error('Synthetic failure'))}>Reject</button><button onClick={retry}>New attempt</button><Boundary key={job.id}><Suspense fallback={<p role="status">Waiting for record</p>}><Record promise={job.resource.promise}/></Suspense></Boundary></section>;}Reject the first pending attempt: the error view should replace the reader. Choose New attempt to create a fresh promise and reset the boundary identity, then Resolve to reveal the successful text. Settled promises cannot change outcome, so resolving the rejected attempt is not a retry. The fixture attaches a no-op rejection observer to avoid an unhandled rejection before the reader mounts; it still passes the original rejecting Promise to use. It has no network operations. Real applications need scoped cache keys, invalidation, resource limits and a retry policy. This class boundary is intentionally minimal; it handles descendant render errors, not arbitrary asynchronous callback failures.
Read context conditionally
import React,{Suspense,use,useState,createContext,Component} from 'react';const Preferences=createContext('Compact');function Detail({open}){if(!open)return null;const layout=use(Preferences);return <p>Detail layout: {layout}</p>;}export default function App(){const [open,setOpen]=useState(false);return <Preferences.Provider value="Expanded"><button onClick={()=>setOpen(v=>!v)} aria-expanded={open} aria-controls="details">Toggle detail</button><div id="details"><Detail open={open}/></div></Preferences.Provider>;}The closed view has no detail text. Opening reads the nearest provider and displays Expanded. This is the documented conditional use exception; useState and useContext must still obey the ordinary top-level rule. Do not call use from event handlers. Practice: reproduce pending, rejection, retry and success with the controlled resource. Explain why a new resource and a reset boundary solve different problems.