import { useEffect, useRef } from "react";
function useWatch(dep, callback) {
    var config = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
        immediate: false
    };
    var immediate = config.immediate;
    var prev = useRef();
    var inited = useRef(false);
    var stop = useRef(false);
    useEffect(function() {
        var execute = function() {
            return callback(prev.current);
        };
        if (!stop.current) {
            if (!inited.current) {
                inited.current = true;
                if (immediate) {
                    execute();
                }
            } else {
                execute();
            }
            prev.current = dep;
        }
    }, [
        dep
    ]);
    return function() {
        stop.current = true;
    };
}
export default useWatch;
