useCancelablePromise()
Home > @gooddata/sdk-ui > useCancelablePromise
useCancelablePromise() function
This hook provides easy way to work with Promises in React components.
Signature:
export declare function useCancelablePromise<TResult, TError = any>(options: UseCancelablePromiseOptions<TResult, TError>, deps?: DependencyList): UseCancelablePromiseState<TResult, TError>;
Parameters
Parameter | Type | Description |
---|---|---|
options | UseCancelablePromiseOptions<TResult, TError> | |
deps | DependencyList | (Optional) |
Returns:
UseCancelablePromiseState<TResult, TError>
Remarks
You can: - watch it's status (pending/loading/success/error) - get it's result/error when the Promise is resolved/rejected, - attach convenient callbacks to it - be sure, that when the dependency list changes, result will be still relevant (if previous Promise is still running, it's "canceled").
Note that it's not recommended to use this hook for storing data on the backend as it does not cancel requests wrapped in these promises and you have no guarantee about the resolution order of the fired requests.