/** * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options */ /** * A hook that allows to execute an asynchronous function and provides the state of the execution. * * @param callback The asynchronous function to be executed. * @returns A tuple with the function that triggers the execution and the state of the execution. * * @example * ```tsx * const [ onFetchData, fetchDataStatus ] = useAsyncCallback( async () => { * const response = await fetch( 'https://api.example.com/data' ); * const data = await response.json(); * return data; * } ); * * return ( *
* * { fetchDataStatus.status === 'loading' &&

Loading...

} * { fetchDataStatus.status === 'success' &&
{ JSON.stringify( fetchDataStatus.data, null, 2 ) }
} * { fetchDataStatus.status === 'error' &&

Error: { fetchDataStatus.error.message }

} *
* ); * ``` */ export declare const useAsyncCallback: , R>(callback: (...args: A) => Promise) => AsyncCallbackHookResult; /** * Represents the result of the `useAsyncCallback` hook. */ export type AsyncCallbackHookResult, R> = [ (...args: A) => Promise, AsyncCallbackState ]; /** * Represents the state of an asynchronous callback. */ export type AsyncCallbackState = { status: 'idle'; } | { status: 'loading'; } | { status: 'success'; data: T; } | { status: 'error'; error: any; };