Skip to content

Commit 839082b

Browse files
authored
[Remote-dom]: Migration guide updates (#3011)
* migration guide additions * re-addition
1 parent 0edf32c commit 839082b

File tree

6 files changed

+145
-57
lines changed

6 files changed

+145
-57
lines changed
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import '@shopify/ui-extensions/preact';
22
import {render} from 'preact';
3-
import {
4-
useAttributeValues
5-
} from '@shopify/ui-extensions/checkout/preact';
63

7-
export default async () => {
4+
export default function extension() {
85
render(<Extension />, document.body);
96
}
107

118
function Extension() {
12-
const [includeGift] = useAttributeValues(['includeGift']);
139
return (
1410
<s-checkbox
15-
checked={includeGift === 'yes'}
1611
onChange={onCheckboxChange}
1712
label="Include a complimentary gift"
1813
/>
1914
);
2015
}
2116

22-
async function onCheckboxChange(e) {
23-
const isChecked = e.target.checked;
17+
async function onCheckboxChange(event) {
18+
const isChecked = event.target.checked;
2419

2520
const result = await shopify.applyAttributeChange({
2621
type: 'updateAttribute',
2722
key: 'includeGift',
2823
value: isChecked ? 'yes' : 'no',
2924
});
25+
3026
console.log('applyAttributeChange result', result);
3127
}
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
import {extension, Checkbox} from '@shopify/ui-extensions/checkout';
22

33
export default extension('purchase.checkout.block.render', (root, api) => {
4-
api.attributes.subscribe(() => render(root, api));
5-
render(root, api);
6-
});
7-
8-
function render(root, api) {
9-
const includeGift = api.attributes.current.some(
10-
(attribute) => attribute.key == 'includeGift' && attribute.value == 'yes',
11-
);
12-
134
async function onCheckboxChange(isChecked) {
145
const result = await api.applyAttributeChange({
156
type: 'updateAttribute',
167
key: 'includeGift',
178
value: isChecked ? 'yes' : 'no',
189
});
10+
1911
console.log('applyAttributeChange result', result);
2012
}
2113

2214
root.replaceChildren(
2315
root.createComponent(
2416
Checkbox,
25-
{checked: includeGift, onChange: onCheckboxChange},
17+
{
18+
onChange: onCheckboxChange,
19+
},
2620
'Include a complimentary gift',
2721
),
2822
);
29-
}
23+
});

packages/ui-extensions/docs/surfaces/checkout/staticPages/examples/upgrading-to-2025-10/apis-old-react.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import {
22
reactExtension,
33
Checkbox,
4-
useAttributeValues,
5-
useApplyAttributeChange,
4+
useApi,
65
} from '@shopify/ui-extensions-react/checkout';
76

87
export default reactExtension('purchase.checkout.block.render', () => (
98
<Extension />
109
));
1110

1211
function Extension() {
13-
const [includeGift] = useAttributeValues(['includeGift']);
14-
const applyAttributeChange = useApplyAttributeChange();
12+
const api = useApi();
1513

1614
async function onCheckboxChange(isChecked) {
17-
const result = await applyAttributeChange({
15+
const result = await api.applyAttributeChange({
1816
type: 'updateAttribute',
1917
key: 'includeGift',
2018
value: isChecked ? 'yes' : 'no',
2119
});
20+
2221
console.log('applyAttributeChange result', result);
2322
}
2423

25-
const checked = includeGift === 'yes';
2624
return (
27-
<Checkbox checked={checked} onChange={onCheckboxChange}>
25+
<Checkbox onChange={onCheckboxChange}>
2826
Include a complimentary gift
2927
</Checkbox>
3028
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import '@shopify/ui-extensions/preact';
2+
import {render} from 'preact';
3+
import {useAttributeValues} from '@shopify/ui-extensions/checkout/preact';
4+
5+
export default function extension() {
6+
render(<Extension />, document.body);
7+
}
8+
9+
function Extension() {
10+
const [includeGift] = useAttributeValues(['includeGift']);
11+
return (
12+
<s-checkbox
13+
checked={includeGift === 'yes'}
14+
onChange={onCheckboxChange}
15+
label="Include a complimentary gift"
16+
/>
17+
);
18+
}
19+
20+
async function onCheckboxChange(event) {
21+
const isChecked = event.target.checked;
22+
23+
const result = await shopify.applyAttributeChange({
24+
type: 'updateAttribute',
25+
key: 'includeGift',
26+
value: isChecked ? 'yes' : 'no',
27+
});
28+
29+
console.log('applyAttributeChange result', result);
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
reactExtension,
3+
Checkbox,
4+
useAttributeValues,
5+
useApplyAttributeChange,
6+
} from '@shopify/ui-extensions-react/checkout';
7+
8+
export default reactExtension('purchase.checkout.block.render', () => (
9+
<Extension />
10+
));
11+
12+
function Extension() {
13+
const [includeGift] = useAttributeValues(['includeGift']);
14+
const applyAttributeChange = useApplyAttributeChange();
15+
16+
async function onCheckboxChange(isChecked) {
17+
const result = await applyAttributeChange({
18+
type: 'updateAttribute',
19+
key: 'includeGift',
20+
value: isChecked ? 'yes' : 'no',
21+
});
22+
23+
console.log('applyAttributeChange result', result);
24+
}
25+
26+
return (
27+
<Checkbox checked={includeGift === 'yes'} onChange={onCheckboxChange}>
28+
Include a complimentary gift
29+
</Checkbox>
30+
);
31+
}

0 commit comments

Comments
 (0)