This hook subscribes to an observable and returns the value of the observable.

Imports

import { useObservable } from '@river-build/react-sdk'

Definition

function useObservable<T>(
  observable: Observable<T>,
  config?: ObservableConfig.FromData<T>,
): ObservableValue<T>

Source: useObservable

Parameters

observable

  • Type: Observable<T>

The observable to subscribe to.

config

  • Type: ObservableConfig.FromData<T>
  • Optional

Configuration options for the observable.

config.fireImmediately

  • Type: boolean
  • Optional

Trigger the update immediately, without waiting for the first update.

config.onError

  • Type: (error: Error) => void
  • Optional

Callback function to be called when an error occurs.

config.onUpdate

  • Type: (data: Data) => void
  • Optional

Callback function to be called when the data is updated.

Return Type

The value of the observable.

ObservableValue<T>