use
use
is a polyfill hook to resolve promises state for React v18 and below. Note that it only implements the ability to consume promises.
Usage
Live Editor
const promise = new Promise((resolve) => { setTimeout(() => { resolve("resolved"); }, 5000); }); function Demo() { const data = use(promise); return <p>{data}</p>; } render( <Suspense fallback="loading..."> <Demo /> </Suspense> );
Result
Loading...
API
Use
Returns
T
: resolved state value
Arguments
Argument | Description | Type | DefaultValue |
---|---|---|---|
usable | promise or context | Usable<T> (Required) | - |
Usable
type Usable<T> = Thenable<T> | Context<T>;