import { useRef, useInsertionEffect, useCallback } from "react"; const useSafeInsertionEffect = typeof window !== "undefined" ? useInsertionEffect : (fn: () => void) => { fn(); }; // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type export const useEffectEvent = (callback?: T) => { const ref = useRef(callback); useSafeInsertionEffect(() => { ref.current = callback; }); return useCallback( ((...args: unknown[]) => ref.current?.(...args)) as never, [] ); };