Skip to content

useLivePreview

useLivePreview<TCollectionSlug>(doc, collectionSlug): DocumentByResourceSlug<TCollectionSlug> | null | undefined

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

Overlays unsaved editor values onto a document a consumer already fetched. collectionSlug accepts a global’s slug too — the same overlay serves both, and announces this render site to the admin panel via the mount handshake.

collectionSlug is a required second argument, not inferred from doc — it is what types doc/the return value to the exact generated document interface for that collection. It also supplies the handshake/update messages’ collectionSlug, which has no other source once doc is null.

TCollectionSlug extends string = string

DocumentByResourceSlug<TCollectionSlug> | null | undefined

The document as fetched by the consumer’s own query, or null/undefined while loading or for a not-yet-saved document.

TCollectionSlug

The collection doc belongs to.

DocumentByResourceSlug<TCollectionSlug> | null | undefined

doc overlaid with unsaved values matching its _id, or — when doc is absent and the current URL carries a vexLivePreviewId matching an entry in the map — a document synthesized from the unsaved values alone.