/** * @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 ( *
Loading...
} * { fetchDataStatus.status === 'success' &&{ JSON.stringify( fetchDataStatus.data, null, 2 ) } }
* { fetchDataStatus.status === 'error' && Error: { fetchDataStatus.error.message }
} *