first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import {useEffect, useMemo, useRef} from 'react';
/**
* 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
*/
export function useCallbackRef<T extends (...args: any[]) => any>(
callback: T | undefined
): T {
const callbackRef = useRef(callback);
useEffect(() => {
callbackRef.current = callback;
});
// https://github.com/facebook/react/issues/19240
return useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, []);
}