Skip to content

useLivePreviewDocumentQuery

useLivePreviewDocumentQuery<TCollectionSlug, TData, TQueryKey>(queryOptions, collectionSlug): LivePreviewDocumentQueryResult<TCollectionSlug>

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

Sugar composing useQuery with useLivePreview for a query that already resolves to a SINGLE document — a getFirst-style singleton read, or any lookup by id — rather than the array useLivePreviewQuery narrows.

Exists because the overlay only reaches documents a consumer hands it: a component fetching an editable document through a plain useQuery is invisible to live preview, which is why editing a headers document while previewing the home page changed nothing.

TCollectionSlug extends string = string

TData extends unknown = DocumentByResourceSlug<TCollectionSlug> | null

TQueryKey extends readonly unknown[] = readonly unknown[]

UseQueryOptions<TData, Error, TData, TQueryKey>

The useQuery options for a query resolving to one document.

TCollectionSlug

The collection that document belongs to.

LivePreviewDocumentQueryResult<TCollectionSlug>

The query result with data overlaid by any unsaved editor values.

const { data: header } = useLivePreviewDocumentQuery(
{ ...convexQuery(api.headers.getFirst, {}), initialData },
"headers",
);