import { useRef, useCallback } from 'react';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect.mjs';

/**
 * Use this for callbacks that are not called during render, most commonly event callbacks.
 * The returned callback will never change and therefore trigger unwanted effects
 * when used in deps or re-render of memoized components.
 * This is a copy of proposed the useEvent hook.
 */ const useEvent = (fn)=>{
    const handlerRef = useRef(fn);
    useIsomorphicLayoutEffect(()=>{
        handlerRef.current = fn;
    }, [
        fn
    ]);
    return useCallback((...args)=>{
        const fn = handlerRef.current;
        return fn(...args);
    }, []);
};

export { useEvent };
//# sourceMappingURL=useEvent.mjs.map
