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

Imports

import { useObservable } from '@towns-protocol/react-sdk'

Definition

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

Source: useObservable

Parameters

observable

  • Type: Observable<Model>

The observable to subscribe to.

config

  • Type: ObservableConfig.FromData<Model>
  • 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<Data>