[**@wocart/theme v4.1.0**](../../README)

***

[@wocart/theme](../../README) / [astro](../README) / previewTarget

# Function: previewTarget()

> **previewTarget**(`theme`, `draft`, `client`): `Promise`\<[`PreviewTarget`](../interfaces/PreviewTarget)\>

What an editor's preview of `draft` renders, or null — answer 404 — for a
surface the theme does not declare:

- A template previews the resource the draft's `path` names
  (`/products/robe`), else the store's first product, category, default
  collection or text page. A store with none still previews: `params` is
  empty and the template renders empty, so its sections can be arranged.
- An area (the header, the footer) previews on the page its `path` names
  when the theme composes that page, else on the home page.
- The resource is chosen by the surface's `pageType`, never its key, so an
  alternate (`product.compact`) previews like its base.
- A landing page's own document (`lp:<id>`) previews with the theme's
  `landing` surface on the page its `path` names (`/lp/<slug>`), and the
  target keeps its own surface, so the sections render that page's document.

```astro
---
const target = await previewTarget(theme, Astro.locals.preview.draft, Astro.locals.store.client);
if (!target) return new Response(null, { status: 404, headers: { "Cache-Control": "no-store" } });
---
<Sections surface={target.surface} params={target.params} document={target.document} preview={target.area === null} />
```

## Parameters

### theme

[`ThemeDefinition`](../../index/interfaces/ThemeDefinition)

### draft

`PreviewDraft`

### client

#### cart

`CartNamespace`

#### categories

`CategoriesNamespace`

#### collections

`CollectionsNamespace`

#### config

`ConfigNamespace`

#### geo

`GeoNamespace`

#### menus

`MenusNamespace`

#### orders

`OrdersNamespace`

#### pageData

`PageDataNamespace`

#### pages

`PagesNamespace`

#### products

`ProductsNamespace`

#### shipping

`ShippingNamespace`

## Returns

`Promise`\<[`PreviewTarget`](../interfaces/PreviewTarget)\>
