Developers
Start building
Themes/Theme SDK/Modules/editor/Hooks

Hooks

The hooks of @poltura/theme-sdk/editor.

On this page
import { … } from '@poltura/theme-sdk/editor';

useIsEditing

Whether the page is drawn inside the customizer canvas.

useIsEditing(): boolean

Returns: True on the customizer canvas, false on the live storefront.

Example

import { useIsEditing } from '@poltura/theme-sdk/editor';

export function EmptyHint({ count }: { count: number }) {
  const editing = useIsEditing();
  return count === 0 && editing ? <p>Add a product to this rail.</p> : null;
}

usePreviewScenario

The choice the customizer's Data picker made for a preview domain.

usePreviewScenario(key: string): string

Outside the customizer it is always the domain's first choice, so branching on it costs nothing live.

Parameters

  • key: string: The domain key, a system one such as cart or one the theme declares.

Returns: The chosen value, or '' for a domain nobody declares.

Example

import { usePreviewScenario } from '@poltura/theme-sdk/editor';

export function Reviews({ count }: { count: number }) {
  const shown = usePreviewScenario('reviews') === 'empty' ? 0 : count;
  return <p>{shown} reviews</p>;
}
Last updated