import { useMemo, useState, useEffect, useCallback } from "react";
export function useDBRaw({ initialState, getter, setter: setterRaw, selector, }) {
    const [state, setState] = useState(initialState);
    useEffect(() => {
        getter().then(state => {
            if (!state) {
                setterRaw(initialState);
                return;
            }
            setState(state);
        });
        // Run once on mount
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    const setter = useCallback(async (newState) => {
        const val = typeof newState === "function" ? newState(await getter()) : newState;
        setState(val);
        return setterRaw(val);
    }, [getter, setterRaw]);
    const result = useMemo(() => selector(state), [state, selector]);
    return [result, setter];
}
//# sourceMappingURL=useDBRaw.js.map