useQueryRef
useQueryRef<
TQueryable>(queryable,options?):object
Defined in: packages/@livestore/react/src/useQuery.ts:60
Like useQuery, but also returns a reference to the underlying LiveQuery instance.
Usage
- Accepts any
Queryable<TResult>: aLiveQueryDef,SignalDef, aLiveQueryinstance or a SQLQueryBuilder. Unions of queryables are supported and the result type is inferred viaQueryable.Result<TQueryable>. - Creates an OpenTelemetry span per unique query, reusing it while the ref-counted resource is alive. The span name is updated once the dynamic label is known.
- Manages a reference-counted resource under-the-hood so query instances are shared across re-renders and properly disposed once no longer referenced.
Parameters
queryable: The query definition/instance/builder to run and subscribe to.options.store: Optional store to use; by default the store fromLiveStoreContextis used.options.otelContext: Optional parent otel context for the query span.options.otelSpanName: Optional explicit span name; otherwise derived from the query label.
Returns
valueRef: A React ref whosecurrentholds the latest query result. The type isQueryable.Result<TQueryable>with full inference for unions.queryRcRef: The underlying reference-countedLiveQueryinstance used by the store.
Type Parameters
Section titled “Type Parameters”TQueryable
Section titled “TQueryable”TQueryable extends Queryable<any>
Parameters
Section titled “Parameters”queryable
Section titled “queryable”TQueryable
options?
Section titled “options?”otelContext?
Section titled “otelContext?”Context
Parent otel context for the query
otelSpanName?
Section titled “otelSpanName?”string
The name of the span to use for the query
store?
Section titled “store?”Store<Any, { }>
Returns
Section titled “Returns”object
queryRcRef
Section titled “queryRcRef”queryRcRef:
RcRef<LiveQuery<Result<TQueryable>>>
valueRef
Section titled “valueRef”valueRef:
RefObject<Result<TQueryable>>