simple-use-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

usePromise

The smallest package to use promises in React.

usePromise.ts is only 60 lines of dependency free Typescript code.

  • Ultra simple to use:
    import { usePromise } from "usePromise";
    // Promise result, undefined when loading, throws on promise rejection
    const result = usePromise(myPromise);
  • Compatible both with ES6 and CommonJS modules

  • useMemoAsync helper for calling async functions:

    // Exact same syntax and behaviour as useMemo, but for promises
    const customer = useMemoAsync(() => fetchCustomer(id), [id]);

No bloat oath

I do solemnly swear to never bloat this package

Rafael Salguero

Package Sidebar

Install

npm i simple-use-promise

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

13.1 kB

Total Files

15

Last publish

Collaborators

  • rafaelsalguero