@equinor/fusion-observable
Version:
21 lines • 790 B
JavaScript
import { useMemo } from 'react';
import { from } from 'rxjs';
import { useObservableState } from './useObservableState';
/**
* React hook that converts an `ObservableInput` (Promise, Iterable, etc.) to
* an RxJS `Observable`. The observable is memoised based on the input reference.
*
* @template T - The value type.
* @param input - Any `ObservableInput<T>`.
* @returns An `Observable<T>` wrapping the input.
*/
export const useObservableInput = (input) => {
return useMemo(() => from(input), [input]);
};
/**
* @see {@link useObservableInputState} — overload without a required initial value.
*/
export function useObservableInputState(input, initial) {
return useObservableState(useObservableInput(input), { initial });
}
//# sourceMappingURL=useObservableInput.js.map