npm.io
2.1.0 • Published 3 years ago

react-promise-client

Licence
MIT
Version
2.1.0
Deps
0
Size
4 kB
Vulns
0
Weekly
0

React promise client

This is a lightweight promise handler.

using npm

npm i react-promise-client

In React:

    const { data, isLoading, execute } = usePromise({
            promiseFn: ()=> asyncAwaitFunction(),
            onSuccess results => console.log(results),
            onFailure: error => console.log(error);
    }, [...deps])

    return isLoading? <div>Loading...</div> : <div>done...</div>
  • execute: execute promise manually and wait for results in data.
  • data: results from promise call.
  • isLoading: true when busy, else false.
  • deps: dependencies like any other hook, this is optional

Keywords