'use client';
import { useEffect, useRef } from 'react';
/**
 * A hook that will throttle the execution of a callback function inside a useEffect.
 * This is useful for things like throttling loading states or other UI updates.
 * @param callback The callback function to be executed.
 * @param delay The delay in milliseconds to throttle the callback.
 * @param deps The dependencies to watch for changes.
 */ export const useThrottledEffect = (callback, delay, deps = [])=>{
    const lastRan = useRef(Date.now());
    useEffect(()=>{
        const handler = setTimeout(()=>{
            if (Date.now() - lastRan.current >= delay) {
                callback();
                lastRan.current = Date.now();
            }
        }, delay - (Date.now() - lastRan.current));
        return ()=>{
            clearTimeout(handler);
        };
    }, [
        delay,
        ...deps
    ]);
};

//# sourceMappingURL=useThrottledEffect.js.map