MCPcopy Create free account
hub / github.com/ckeditor/ckeditor5-react / useAsyncValue

Function useAsyncValue

src/hooks/useAsyncValue.ts:40–58  ·  view source on GitHub ↗
(
	callback: () => Promise<R>,
	deps: DependencyList
)

Source from the content-addressed store, hash-verified

38 * ```
39 */
40export const useAsyncValue = <R>(
41 callback: () => Promise<R>,
42 deps: DependencyList
43): AsyncValueHookResult<R> => {
44 const [ asyncCallback, asyncState ] = useAsyncCallback( callback );
45
46 useInstantEffect( asyncCallback, deps );
47
48 // There might be short delay between the effect and the state update.
49 // So it is possible that the status is still 'idle' after the effect.
50 // In such case, we should return 'loading' status because the effect is already queued to be executed.
51 if ( asyncState.status === 'idle' ) {
52 return {
53 status: 'loading'
54 };
55 }
56
57 return asyncState;
58};
59
60/**
61 * The result of the `useAsyncValue` hook.

Callers 2

useCKEditorCloudFunction · 0.85

Calls 2

useAsyncCallbackFunction · 0.85
useInstantEffectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…