Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-lemons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': patch
---

Add Preact Signal code examples to Checkout UI api docs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default function extension() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default function extension() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useNote} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const note = useNote();
return <s-text>Note: {note}</s-text>;
return (
<s-text>Note: {shopify.note.value}</s-text>
);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
// As of version 2025-10, you no longer need the `useApi` hook.
// The full API object is accessible via the global `shopify` object.
return (
<s-text>
Shop name: {shopify.shop.name}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useAttributeValues} from '@shopify/ui-extensions/checkout/preact';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useAttributeValues,
useApplyAttributeChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';
import {useAttributeValues} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
Expand All @@ -14,17 +11,14 @@ function Extension() {
'giftWrap',
]);
const giftWrap = Boolean(giftWrapValue);
const applyAttributeChange =
useApplyAttributeChange();
const instructions = useInstructions();

async function toggleGiftWrap() {
const result = giftWrap
? await applyAttributeChange({
? await shopify.applyAttributeChange({
type: 'removeAttribute',
key: 'giftWrap',
})
: await applyAttributeChange({
: await shopify.applyAttributeChange({
type: 'updateAttribute',
key: 'giftWrap',
value: 'true',
Expand All @@ -43,7 +37,7 @@ function Extension() {
<s-button
onClick={toggleGiftWrap}
disabled={
!instructions.attributes
!shopify.instructions.value.attributes
.canUpdateAttributes
}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useState} from 'preact/hooks';
import {
useBuyerJourneyIntercept,
useCartLineTarget,
} from '@shopify/ui-extensions/checkout/preact';
import {useBuyerJourneyIntercept} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
Expand All @@ -12,11 +10,11 @@ export default function extension() {
function Extension() {
const [showError, setShowError] =
useState(false);
const {quantity} = useCartLineTarget();

useBuyerJourneyIntercept(
({canBlockProgress}) => {
return canBlockProgress && quantity > 1
return canBlockProgress &&
shopify.target.value.quantity > 1
? {
behavior: 'block',
reason: 'limited stock',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useBuyerJourneyIntercept,
useShippingAddress,
} from '@shopify/ui-extensions/checkout/preact';
import {useBuyerJourneyIntercept} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const address = useShippingAddress();

useBuyerJourneyIntercept(
({canBlockProgress}) => {
return canBlockProgress &&
address?.countryCode &&
address.countryCode !== 'CA'
shopify.shippingAddress.value
?.countryCode &&
shopify.shippingAddress.value
.countryCode !== 'CA'
? {
behavior: 'block',
reason: 'Invalid shipping country',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useBuyerJourneyIntercept,
useShippingAddress,
} from '@shopify/ui-extensions/checkout/preact';
import {useBuyerJourneyIntercept} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const address = useShippingAddress();

useBuyerJourneyIntercept(
({canBlockProgress}) => {
return canBlockProgress &&
address?.countryCode &&
address.countryCode !== 'CA'
shopify.shippingAddress.value
?.countryCode &&
shopify.shippingAddress.value
.countryCode !== 'CA'
? {
behavior: 'block',
reason: 'Invalid shipping country',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useApplyAttributeChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const applyAttributeChange =
useApplyAttributeChange();
const instructions = useInstructions();

if (
instructions.attributes.canUpdateAttributes
shopify.instructions.value.attributes
.canUpdateAttributes
) {
return (
<s-button
onClick={() =>
applyAttributeChange({
shopify.applyAttributeChange({
type: 'updateAttribute',
key: 'loyaltyPoints',
value: '100',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useApplyCartLinesChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const applyCartLinesChange =
useApplyCartLinesChange();
const instructions = useInstructions();

if (instructions.lines.canAddCartLine) {
if (
shopify.instructions.value.lines
.canAddCartLine
) {
return (
<s-button
onClick={() =>
applyCartLinesChange({
shopify.applyCartLinesChange({
type: 'addCartLine',
merchandiseId:
'gid://shopify/product/1234',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useApplyShippingAddressChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const applyShippingAddressChange =
useApplyShippingAddressChange();
const instructions = useInstructions();

if (
instructions.delivery.canSelectCustomAddress
shopify.instructions.value.delivery
.canSelectCustomAddress
) {
return (
<s-button
onClick={() =>
applyShippingAddressChange({
shopify.applyShippingAddressChange({
type: 'updateShippingAddress',
address: {
zip: '90201',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useApplyDiscountCodeChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const applyDiscountCodeChange =
useApplyDiscountCodeChange();
const instructions = useInstructions();

if (
instructions.discounts.canUpdateDiscountCodes
shopify.instructions.value.discounts
.canUpdateDiscountCodes
) {
return (
<s-button
onClick={() =>
applyDiscountCodeChange({
shopify.applyDiscountCodeChange({
type: 'addDiscountCode',
code: 'FREE_SHIPPING',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useApplyMetafieldChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const applyMetafieldChange =
useApplyMetafieldChange();
const instructions = useInstructions();

if (
instructions.metafields.canSetCartMetafields
shopify.instructions.value.metafields
.canSetCartMetafields
) {
return (
<s-button
onClick={() =>
applyMetafieldChange({
shopify.applyMetafieldChange({
type: 'updateCartMetafield',
metafield: {
namespace: 'loyalty',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {
useApplyNoteChange,
useInstructions,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const applyNoteChange = useApplyNoteChange();
const instructions = useInstructions();

if (instructions.notes.canUpdateNote) {
if (
shopify.instructions.value.notes.canUpdateNote
) {
return (
<s-button
onClick={() =>
applyNoteChange({
shopify.applyNoteChange({
type: 'updateNote',
note: 'Please include a free gift.',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useCartLineTarget} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const {
merchandise: {title},
} = useCartLineTarget();
return (
<s-text>Line item title: {title}</s-text>
<s-text>
Line item title:{' '}
{shopify.target.value.merchandise.title}
</s-text>
);
}
Loading
Loading