import { useEffect, useRef } from "react";
import isEqual from "lodash/isEqual";
function useDeepCompareMemoize(value) {
    const ref = useRef();
    if (!isEqual(value, ref.current)) {
        ref.current = value;
    }
    return ref.current;
}
/**
 * Use this just like useEffect() except that this will compare objects and arrays using lodash's isEqual() method.
 * Always pass an array of dependencies as the second parameter!!!
 */
export function useDeepEffect(callback, dependencies) {
    useEffect(callback, useDeepCompareMemoize(dependencies));
}
/*
// Previous implementation that had bugs. Keep around for a bit until we shake out the new version.
export function useDeepEffect(effectFunc : Function, deps : Array<any>) {
    const isFirst = useRef(true);
    const prevDeps = useRef(deps);

    useEffect(() => {
        const isSame = prevDeps.current.every((obj: any, index: any) => isEqual(obj, deps[index]));
        if (isFirst.current || !isSame) {
            effectFunc();
        }

        isFirst.current = false;
        prevDeps.current = deps;
    }, deps);
}
*/
//# sourceMappingURL=useDeepEffect.js.map