import { ReplaySubject } from "rxjs";
import { useEffect, useState } from "react";
// emit value each time it changes by reference. it replays the last value at subscribe time.
export function useReplaySubject(value) {
    const [subject] = useState(() => new ReplaySubject());
    useEffect(() => {
        subject.next(value);
    }, [subject, value]);
    useEffect(() => {
        return () => {
            subject.complete();
        };
    }, [subject]);
    return subject;
}
export function useObservable(observable, initialValue) {
    const [value, update] = useState(initialValue || undefined);
    useEffect(() => {
        const s = observable.subscribe(update);
        return () => s.unsubscribe();
    }, [observable]);
    return value;
}
//# sourceMappingURL=observable.js.map