1.0.2 • Published 2 years ago

simple-use-promise v1.0.2

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

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