import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useEffectOnce, useLatest } from 'react-use';
import { debounce } from "../lodash.js";
export const useElementState = () => useState(null);
export function useBooleanState(initial) {
    const [value, setValue] = useState(initial);
    return [
        value,
        useCallback(() => setValue(true), []),
        useCallback(() => setValue(false), []),
        useCallback(() => setValue((val) => !val), []),
    ];
}
export const useComponentWillMount = (cb) => {
    const willMount = useRef(true);
    if (willMount.current)
        cb();
    willMount.current = false;
};
export const useRenderTime = (cb) => {
    let time = 0;
    useComponentWillMount(() => {
        time = Date.now();
    });
    useEffectOnce(() => {
        cb(Date.now() - time);
    });
};
export function useDebounce(cb, wait) {
    const latestCb = useLatest(cb);
    const debouncedFn = useMemo(() => debounce((...args) => {
        latestCb.current.apply(null, args);
    }, wait), [latestCb, wait]);
    // cancel function on unmount
    useEffect(() => () => debouncedFn.cancel(), [debouncedFn]);
    return debouncedFn;
}
export { useAutoSave, } from "./hooks/useAutoSave.js";
//# sourceMappingURL=hooks.js.map
