import { useRef } from "react"; type noop = (...args: any[]) => any; /** * usePersistFn instead of useCallback to reduce cognitive load */ export function usePersistFn(fn: T) { const fnRef = useRef(fn); fnRef.current = fn; const persistFn = useRef(null); if (!persistFn.current) { persistFn.current = function (this: unknown, ...args) { return fnRef.current!.apply(this, args); } as T; } return persistFn.current!; }