@jeswr/use-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i @jeswr/use-promise

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

6.22 kB

Total Files

5

Last publish

Collaborators

  • jeswr