Sanity App SDK
    Preparing search index...

    Interface StateSource<T>

    Represents a reactive state source that provides synchronized access to store data

    Designed to work with React's useSyncExternalStore hook. Provides three ways to access data:

    1. getCurrent() for synchronous current value access
    2. subscribe() for imperative change notifications
    3. observable for reactive stream access
    interface StateSource<T> {
        getCurrent: () => T;
        observable: Observable<T>;
        subscribe: (onStoreChanged?: () => void) => () => void;
    }

    Type Parameters

    • T
    Index

    Properties

    getCurrent: () => T

    Gets the current derived state value

    Safe to call without subscription. Will always return the latest value based on the current store state and selector parameters.

    observable: Observable<T>

    Observable stream of state values

    Shares a single underlying subscription between all observers. Emits:

    • Immediately with current value on subscription
    • On every relevant state change
    • Errors if selector throws
    subscribe: (onStoreChanged?: () => void) => () => void

    Subscribes to state changes with optional callback

    Type declaration

      • (onStoreChanged?: () => void): () => void
      • Parameters

        • OptionalonStoreChanged: () => void

          Called whenever relevant state changes occur

        Returns () => void

        Unsubscribe function to clean up the subscription