function useLiveQuery<TContext>(queryFn): QueryResult<TContext>;Defined in: useLiveQuery.ts:153
Subscribe a Preact component to a live query.
The hook derives the query's identity from its structured IR on each render, so values captured by the callback recompile the query when they change. A query whose IR cannot be hashed, such as one using fn.where, throws UnhashableQueryIRError unless its config supplies queryKey. While the hook is mounted, each Collection ID its queries read must keep naming one source object, or it throws SourceCollectionIdReuseError. Return undefined or null from the callback to disable the query.
TContext extends Context
(q) => QueryBuilder<TContext>
QueryResult<TContext>
const { data, isLoading } = useLiveQuery((q) =>
q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.completed, false)),
)// Disable the query until its input exists
const { data, isEnabled } = useLiveQuery((q) =>
userId
? q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.userId, userId))
: undefined,
)function useLiveQuery<TContext>(queryFn): ConditionalQueryResult<TContext>;Defined in: useLiveQuery.ts:157
Subscribe a Preact component to a live query.
The hook derives the query's identity from its structured IR on each render, so values captured by the callback recompile the query when they change. A query whose IR cannot be hashed, such as one using fn.where, throws UnhashableQueryIRError unless its config supplies queryKey. While the hook is mounted, each Collection ID its queries read must keep naming one source object, or it throws SourceCollectionIdReuseError. Return undefined or null from the callback to disable the query.
TContext extends Context
(q) => QueryBuilder<TContext> | null | undefined
ConditionalQueryResult<TContext>
const { data, isLoading } = useLiveQuery((q) =>
q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.completed, false)),
)// Disable the query until its input exists
const { data, isEnabled } = useLiveQuery((q) =>
userId
? q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.userId, userId))
: undefined,
)function useLiveQuery<TContext>(queryFn): ConditionalQueryResult<TContext>;Defined in: useLiveQuery.ts:163
Subscribe a Preact component to a live query.
The hook derives the query's identity from its structured IR on each render, so values captured by the callback recompile the query when they change. A query whose IR cannot be hashed, such as one using fn.where, throws UnhashableQueryIRError unless its config supplies queryKey. While the hook is mounted, each Collection ID its queries read must keep naming one source object, or it throws SourceCollectionIdReuseError. Return undefined or null from the callback to disable the query.
TContext extends Context
(q) => | LiveQueryCollectionConfig<TContext, RootQueryResult<TContext>> | null | undefined
ConditionalQueryResult<TContext>
const { data, isLoading } = useLiveQuery((q) =>
q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.completed, false)),
)// Disable the query until its input exists
const { data, isEnabled } = useLiveQuery((q) =>
userId
? q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.userId, userId))
: undefined,
)function useLiveQuery<TResult, TKey, TUtils>(queryFn): UseConditionalLiveQueryResult<TResult, TKey, TResult[], Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult>>;Defined in: useLiveQuery.ts:169
Subscribe a Preact component to a live query.
The hook derives the query's identity from its structured IR on each render, so values captured by the callback recompile the query when they change. A query whose IR cannot be hashed, such as one using fn.where, throws UnhashableQueryIRError unless its config supplies queryKey. While the hook is mounted, each Collection ID its queries read must keep naming one source object, or it throws SourceCollectionIdReuseError. Return undefined or null from the callback to disable the query.
TResult extends object
TKey extends string | number
TUtils extends Record<string, any>
(q) => | Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult> | null | undefined
UseConditionalLiveQueryResult<TResult, TKey, TResult[], Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult>>
const { data, isLoading } = useLiveQuery((q) =>
q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.completed, false)),
)// Disable the query until its input exists
const { data, isEnabled } = useLiveQuery((q) =>
userId
? q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.userId, userId))
: undefined,
)function useLiveQuery<TContext>(config): QueryResult<TContext>;Defined in: useLiveQuery.ts:193
Subscribe to a live query described by a config object.
TContext extends Context
UseLiveQueryConfig<TContext>
QueryResult<TContext>
const { data } = useLiveQuery({
query: (q) => q.from({ todos: todosCollection }),
gcTime: 60_000,
})function useLiveQuery<TContext>(config): ConditionalQueryResult<TContext>;Defined in: useLiveQuery.ts:197
Subscribe a Preact component to a live query.
The hook derives the query's identity from its structured IR on each render, so values captured by the callback recompile the query when they change. A query whose IR cannot be hashed, such as one using fn.where, throws UnhashableQueryIRError unless its config supplies queryKey. While the hook is mounted, each Collection ID its queries read must keep naming one source object, or it throws SourceCollectionIdReuseError. Return undefined or null from the callback to disable the query.
TContext extends Context
ConditionalUseLiveQueryConfig<TContext>
ConditionalQueryResult<TContext>
const { data, isLoading } = useLiveQuery((q) =>
q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.completed, false)),
)// Disable the query until its input exists
const { data, isEnabled } = useLiveQuery((q) =>
userId
? q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.userId, userId))
: undefined,
)function useLiveQuery<TResult, TKey, TUtils>(liveQueryCollection): UseLiveQueryResult<TResult, TKey, TResult[], Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult>>;Defined in: useLiveQuery.ts:211
Subscribe to an existing live-query Collection. The hook starts its sync and leaves its retention policy to the caller.
TResult extends object
TKey extends string | number
TUtils extends Record<string, any>
Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult> & NonSingleResult
UseLiveQueryResult<TResult, TKey, TResult[], Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult>>
const activeTodos = createLiveQueryCollection((q) =>
q.from({ todos: todosCollection }).where(({ todos }) => todos.active),
)
const { data, collection } = useLiveQuery(activeTodos)function useLiveQuery<TResult, TKey, TUtils>(liveQueryCollection): UseLiveQueryResult<TResult, TKey, TResult | undefined, Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult> & SingleResult>;Defined in: useLiveQuery.ts:224
Subscribe a Preact component to a live query.
The hook derives the query's identity from its structured IR on each render, so values captured by the callback recompile the query when they change. A query whose IR cannot be hashed, such as one using fn.where, throws UnhashableQueryIRError unless its config supplies queryKey. While the hook is mounted, each Collection ID its queries read must keep naming one source object, or it throws SourceCollectionIdReuseError. Return undefined or null from the callback to disable the query.
TResult extends object
TKey extends string | number
TUtils extends Record<string, any>
Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult> & SingleResult
UseLiveQueryResult<TResult, TKey, TResult | undefined, Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult> & SingleResult>
const { data, isLoading } = useLiveQuery((q) =>
q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.completed, false)),
)// Disable the query until its input exists
const { data, isEnabled } = useLiveQuery((q) =>
userId
? q
.from({ todos: todosCollection })
.where(({ todos }) => eq(todos.userId, userId))
: undefined,
)