useCancelablePromiseMaker
FunctionuseCancelablePromiseMaker(): <T>(p: Promise<T>) => CancelablePromise<T>This hook returns a function named cancelable .
Input of cancelable is a common promise and output of it is a cancelable promise (see jimu-core cancelablePromise.cancelable for more details).
If components are to unmount, the hook will help to cancel all promises.
example:
const Component = () => {
const cancelable = useCancelablePromiseMaker()
const [data, setData] = useState()
useEffect(() => {
const promise = cancelable(fetchData())
promise.then((data) => {
setData(data)
})
}, [])
return <div />Returns
<T>(p: Promise<T>) => CancelablePromise<T>function<T>(p: Promise<T>): CancelablePromise<T>Type Parameters
| Parameter | Type |
|---|---|
T |
Parameters
| Parameter | Type |
|---|---|
p | Promise<T> |
Returns
CancelablePromise<T>