1.0.2 • Published 3 years ago

@jeswr/use-promise v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

use-promise

React hook to resolve promises

GitHub license npm version build Dependabot Downloads semantic-release

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.