> ## Documentation Index
> Fetch the complete documentation index at: https://docs.towns.com/llms.txt
> Use this file to discover all available pages before exploring further.

# useObservable

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

## Imports

```ts theme={null}
import { useObservable } from '@towns-protocol/react-sdk'
```

## Definition

```ts theme={null}
function useObservable<Model, Data>(
  observable: Observable<Model>,
  config?: ObservableConfig.FromData<Model>,
): ObservableValue<Data>
```

**Source:** [useObservable](https://github.com/towns-protocol/towns/blob/main/packages/react-sdk/src/useObservable.ts)

## 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.

```ts theme={null}
ObservableValue<Data>
```
