MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / useCallbackRef

Function useCallbackRef

apps/start/src/hooks/use-callback-ref.ts:11–25  ·  view source on GitHub ↗

* A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a * prop or avoid re-executing effects when passed as a dependency

(
  callback: T | undefined,
)

Source from the content-addressed store, hash-verified

9 * prop or avoid re-executing effects when passed as a dependency
10 */
11function useCallbackRef<T extends (...args: never[]) => unknown>(
12 callback: T | undefined,
13): T {
14 const callbackRef = React.useRef(callback);
15
16 React.useEffect(() => {
17 callbackRef.current = callback;
18 });
19
20 // https://github.com/facebook/react/issues/19240
21 return React.useMemo(
22 () => ((...args) => callbackRef.current?.(...args)) as T,
23 [],
24 );
25}
26
27export { useCallbackRef };

Callers 1

useDebouncedCallbackFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected