Hook to get an observable from the sync agent.

An alternative of our premade hooks, allowing the creation of custom abstractions.

Imports

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

Definition

function useRiver<T>(
  selector: (sync: SyncSelector) => Observable<T>,
  config?: ObservableConfig.FromData<T>,
): T extends PersistedModel<infer UnwrappedData> ? {
    data: UnwrappedData;
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
} : {
    data: T;
    error: undefined;
    status: "loading" | "loaded";
    isLoading: boolean;
    isError: false;
    isLoaded: boolean;
}

Source: useRiver

Parameters

selector

  • Type: (sync: SyncSelector) => Observable<T>

A selector function to get a observable from the sync agent.

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 data from the selected observable.

T extends PersistedModel<infer UnwrappedData> ? {
    data: UnwrappedData;
    error: Error | undefined;
    status: "error" | "loading" | "loaded";
    isLoading: boolean;
    isError: boolean;
    isLoaded: boolean;
} : {
    data: T;
    error: undefined;
    status: "loading" | "loaded";
    isLoading: boolean;
    isError: false;
    isLoaded: boolean;
}