Skip to content

useLivePreviewQuery

useLivePreviewQuery<TCollectionSlug, TQueryKey>(queryOptions, collectionSlug): LivePreviewQueryResult<TCollectionSlug>

Defined in: packages/react/src/livePreview/LivePreviewContext.tsx:350

Sugar composing useQuery with useLivePreview — shaped around a getBySlug-style query that resolves to an array, narrowed to its first element the same way PageContent.tsx already does by hand.

TCollectionSlug extends string = string

TQueryKey extends readonly unknown[] = readonly unknown[]

UseQueryOptions<DocumentByResourceSlug<TCollectionSlug>[], Error, DocumentByResourceSlug<TCollectionSlug>[], TQueryKey>

The useQuery options for a query resolving to an array.

TCollectionSlug

The collection those documents belong to.

LivePreviewQueryResult<TCollectionSlug>

The query result with data narrowed to the single overlaid document.

const { data: page } = useLivePreviewQuery(
{ ...convexQuery(api.pages.getBySlug, { slug }), initialData },
"pages",
);