use-promise-call
a React hook for state around promise
Install
// use yarnyarn add use-promise-call// use npmnpm install use-promise-call
API
usePromiseCall
-
usePromiseCall(asyncMethod, parameters, options?) => { data, error, loading, reload }
: usePromiseCall hooks to manage async status inside-
asyncMethod
: The method to run async -
parameters
: The initial parameters to asyncMethod, or function to get initial parameters -
options
: config-
manual
: boolean flag to manual trigger async methoddefault: false
-
initial
:initial data valuedefault: null
default :
{ interval = 100 }
-
-
result
data
: promise resolve valueerror
: promise reject valueloading
: status of async methodreload(parameters?)
: method of re-run async methodrun(parameters?)
: method of manual trigger async method
Demo
Base
const productId = '1'const data: product = return product && <div>productname</div>
Parallel
const productId = '1'const data: product = const data: comments = return product && <div>productname</div>
Dependent
const productId = '1'const data: product loading: productLoading = const data: store loading: storeLoading = return product && <div>productname</div>