Skip to content

Commit 9e9964b

Browse files
committed
update checkout ui extensions code examples to preact signals
1 parent fd91756 commit 9e9964b

File tree

46 files changed

+169
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+169
-235
lines changed

packages/ui-extensions/docs/surfaces/checkout/reference/examples/analytics-publish.example.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
23

34
export default function extension() {

packages/ui-extensions/docs/surfaces/checkout/reference/examples/analytics-visitor.example.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
23

34
export default function extension() {
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
2-
import {useNote} from '@shopify/ui-extensions/checkout/preact';
33

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

88
function Extension() {
9-
const note = useNote();
10-
return <s-text>Note: {note}</s-text>;
9+
return (
10+
<s-text>Note: {shopify.note.value}</s-text>
11+
);
1112
}

packages/ui-extensions/docs/surfaces/checkout/reference/examples/api.example.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
23

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

78
function Extension() {
9+
// As of version 2025-10, you no longer need the `useApi` hook.
10+
// The full API object is accessible via the global `shopify` object.
811
return (
912
<s-text>
1013
Shop name: {shopify.shop.name}

packages/ui-extensions/docs/surfaces/checkout/reference/examples/attribute-values.example.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
23
import {useAttributeValues} from '@shopify/ui-extensions/checkout/preact';
34

packages/ui-extensions/docs/surfaces/checkout/reference/examples/attributes/attribute-change.example.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
2-
import {
3-
useAttributeValues,
4-
useApplyAttributeChange,
5-
useInstructions,
6-
} from '@shopify/ui-extensions/checkout/preact';
3+
import {useAttributeValues} from '@shopify/ui-extensions/checkout/preact';
74

85
export default function extension() {
96
render(<Extension />, document.body);
@@ -14,17 +11,14 @@ function Extension() {
1411
'giftWrap',
1512
]);
1613
const giftWrap = Boolean(giftWrapValue);
17-
const applyAttributeChange =
18-
useApplyAttributeChange();
19-
const instructions = useInstructions();
2014

2115
async function toggleGiftWrap() {
2216
const result = giftWrap
23-
? await applyAttributeChange({
17+
? await shopify.applyAttributeChange({
2418
type: 'removeAttribute',
2519
key: 'giftWrap',
2620
})
27-
: await applyAttributeChange({
21+
: await shopify.applyAttributeChange({
2822
type: 'updateAttribute',
2923
key: 'giftWrap',
3024
value: 'true',
@@ -43,7 +37,7 @@ function Extension() {
4337
<s-button
4438
onClick={toggleGiftWrap}
4539
disabled={
46-
!instructions.attributes
40+
!shopify.instructions.value.attributes
4741
.canUpdateAttributes
4842
}
4943
>

packages/ui-extensions/docs/surfaces/checkout/reference/examples/buyer-journey-intercept/extension-banner.example.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
23
import {useState} from 'preact/hooks';
3-
import {
4-
useBuyerJourneyIntercept,
5-
useCartLineTarget,
6-
} from '@shopify/ui-extensions/checkout/preact';
4+
import {useBuyerJourneyIntercept} from '@shopify/ui-extensions/checkout/preact';
75

86
export default function extension() {
97
render(<Extension />, document.body);
@@ -12,11 +10,11 @@ export default function extension() {
1210
function Extension() {
1311
const [showError, setShowError] =
1412
useState(false);
15-
const {quantity} = useCartLineTarget();
1613

1714
useBuyerJourneyIntercept(
1815
({canBlockProgress}) => {
19-
return canBlockProgress && quantity > 1
16+
return canBlockProgress &&
17+
shopify.target.value.quantity > 1
2018
? {
2119
behavior: 'block',
2220
reason: 'limited stock',

packages/ui-extensions/docs/surfaces/checkout/reference/examples/buyer-journey-intercept/page-level-error.example.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
2-
import {
3-
useBuyerJourneyIntercept,
4-
useShippingAddress,
5-
} from '@shopify/ui-extensions/checkout/preact';
3+
import {useBuyerJourneyIntercept} from '@shopify/ui-extensions/checkout/preact';
64

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

119
function Extension() {
12-
const address = useShippingAddress();
13-
1410
useBuyerJourneyIntercept(
1511
({canBlockProgress}) => {
1612
return canBlockProgress &&
17-
address?.countryCode &&
18-
address.countryCode !== 'CA'
13+
shopify.shippingAddress.value
14+
?.countryCode &&
15+
shopify.shippingAddress.value
16+
.countryCode !== 'CA'
1917
? {
2018
behavior: 'block',
2119
reason: 'Invalid shipping country',

packages/ui-extensions/docs/surfaces/checkout/reference/examples/buyer-journey-intercept/target-native-field.example.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
2-
import {
3-
useBuyerJourneyIntercept,
4-
useShippingAddress,
5-
} from '@shopify/ui-extensions/checkout/preact';
3+
import {useBuyerJourneyIntercept} from '@shopify/ui-extensions/checkout/preact';
64

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

119
function Extension() {
12-
const address = useShippingAddress();
13-
1410
useBuyerJourneyIntercept(
1511
({canBlockProgress}) => {
1612
return canBlockProgress &&
17-
address?.countryCode &&
18-
address.countryCode !== 'CA'
13+
shopify.shippingAddress.value
14+
?.countryCode &&
15+
shopify.shippingAddress.value
16+
.countryCode !== 'CA'
1917
? {
2018
behavior: 'block',
2119
reason: 'Invalid shipping country',

packages/ui-extensions/docs/surfaces/checkout/reference/examples/cart-instructions/attributes.example.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1+
import '@shopify/ui-extensions/preact';
12
import {render} from 'preact';
2-
import {
3-
useApplyAttributeChange,
4-
useInstructions,
5-
} from '@shopify/ui-extensions/checkout/preact';
63

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

118
function Extension() {
12-
const applyAttributeChange =
13-
useApplyAttributeChange();
14-
const instructions = useInstructions();
15-
169
if (
17-
instructions.attributes.canUpdateAttributes
10+
shopify.instructions.value.attributes
11+
.canUpdateAttributes
1812
) {
1913
return (
2014
<s-button
2115
onClick={() =>
22-
applyAttributeChange({
16+
shopify.applyAttributeChange({
2317
type: 'updateAttribute',
2418
key: 'loyaltyPoints',
2519
value: '100',

0 commit comments

Comments
 (0)