Sanity App SDK
    Preparing search index...

    Function getQueryState

    • Beta

      Returns the state source for a query.

      This function returns a state source that represents the current result of a GROQ query. Subscribing to the state source will instruct the SDK to fetch the query (if not already fetched) and will keep the query live using the Live content API (considering sync tags) to provide up-to-date results. When the last subscriber is removed, the query state is automatically cleaned up from the store.

      Note: This functionality is for advanced users who want to build their own framework integrations. Our SDK also provides a React integration (useQuery hook) for convenient usage.

      Note: Automatic cleanup can interfere with React Suspense because if a component suspends while being the only subscriber, cleanup might occur unexpectedly. In such cases, consider using resolveQuery instead.

      Type Parameters

      • TQuery extends string = string
      • TDataset extends string = string
      • TProjectId extends string = string

      Parameters

      Returns StateSource<undefined | SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`>>

    • Beta

      Type Parameters

      • TData

      Parameters

      Returns StateSource<undefined | TData>

    • Beta

      Parameters

      Returns StateSource<unknown>