@jeswr/use-promise
v1.0.2
Published
Takes a logical statement and simplifies it.
Downloads
4
Readme
use-promise
React hook to resolve promises
Usage
The output of the hook is undefined
whilst the promise is unresolved or rejected. When the promise resolves, the output of the hook is the resolved value of the promise.
import usePromise from 'use-promise';
const myPromise = (async () => 'my data')();
function MyReactComponent() {
// usePromise(myPromise) is either 'my data' or undefined
const data: string = usePromise(myPromise) ?? '';
return <div>{data}</div>
}
License
©2021–present Jesse Wright, MIT License.