Skip to content

useCancelablePromiseMaker

Function
useCancelablePromiseMaker(): <T>(pPromise<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:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
const Component = () => {
const cancelable = useCancelablePromiseMaker()
const [data, setData] = useState()
useEffect(() => {
 const promise = cancelable(fetchData())
  promise.then((data) => {
    setData(data)
  })
  }, [])
return <div />
Returns 
<T>(pPromise<T>) => CancelablePromise<T>
    function<T>(pPromise<T>): CancelablePromise<T>
    Type Parameters
    ParameterType
    T
    Parameters
    ParameterType
    pPromise<T>
    Returns 
    CancelablePromise<T>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.