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

Function useRefSafeCallback

src/hooks/useRefSafeCallback.ts:12–20  ·  view source on GitHub ↗
( fn: ( ...args: A ) => R )

Source from the content-addressed store, hash-verified

10 * Useful for preventing closures from capturing cached scope variables (avoiding the stale closure problem).
11 */
12export const useRefSafeCallback = <A extends Array<unknown>, R>( fn: ( ...args: A ) => R ): typeof fn => {
13 const callbackRef = useRef<typeof fn>();
14 callbackRef.current = fn;
15
16 return useCallback(
17 ( ...args: A ): R => ( callbackRef.current as typeof fn )( ...args ),
18 []
19 );
20};

Callers 4

useMultiRootEditorFunction · 0.85
useAsyncCallbackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…