import { useRef, useState } from 'react';
import { useUpdateEffect } from '../useUpdateEffect/index.js';
import { isStrictEqual } from '../util/const.js';
export function usePreviousDistinct(value, predicate = isStrictEqual) {
    const [previousState, setPreviousState] = useState();
    const currentRef = useRef(value);
    useUpdateEffect(() => {
        if (!predicate(currentRef.current, value)) {
            setPreviousState(currentRef.current);
            currentRef.current = value;
        }
    }, [value]);
    return previousState;
}
