import { DependencyList, EffectCallback, useEffect, useRef } from "react";

/**
 * Identical to React.useEffect, except that it never runs on mount. This is
 * the equivalent of the componentDidUpdate lifecycle function.
 */
const useEffectExceptOnMount = (effect: EffectCallback, deps?: DependencyList) => {
    const mounted = useRef(false);
    useEffect(() => {
        if (mounted.current) {
            return effect();
        }

        mounted.current = true;
    }, deps);
};

export default useEffectExceptOnMount;
