Returns the values for the specified `attributes` applied to the checkout.
import React from 'react';
import {
Text,
render,
useAttributeValues,
} from '@shopify/checkout-ui-extensions-react';
render('Checkout::Dynamic::Render', () => (
));
function Extension() {
const [buyerSelectedFreeTShirt, tshirtSize] =
useAttributeValues([
'buyerSelectedFreeTShirt',
'tshirtSize',
]);
if (Boolean(buyerSelectedFreeTShirt) === true) {
return (
You selected a free t-shirt, size:{' '}
{tshirtSize}
);
}
return null;
}
Returns the values for the specified `attributes` applied to the checkout.
keys: string[]
export function useAttributeValues< ID extends RenderExtensionPoint = RenderExtensionPoint, >(keys: string[]): (string | undefined)[] { const attributes = useAttributes<ID>(); if (!attributes?.length) { return []; } return keys.map((key) => { const attribute = attributes.find((attribute) => attribute.key === key); return attribute?.value; }); }