For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
I'm wanting to conditionally display elements in a Checkout UI Extension if settings have been added, but if has_title or has_content_1 fails, none of the elements display.
Is this the correct way to include conditionally logic or is there another way to do it?
function App() {
const { title, heading_1, content_1 } = useSettings();
const has_title = title.trim() !== '';
const has_content_1 = heading_1.trim() !== '' && content_1.trim() !== '';
return (
<>
{has_title && (
<Text emphasis="bold">{title}</Text>
)}
{has_content_1 && (
<View border="none" padding="base">
<Text emphasis="bold">{heading_1}</Text>
<TextBlock>
{content_1}
</TextBlock>
</View>
)}
</>
);
}
Hi Timd,
I've asked the checkouts team about this - will update here when I learn more.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
has_title
or has_content_1
is false, no elements is displayedhas_title
and has_content_1
is true, elements are displayedIs that correct?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi @Liam no it should be the opposite, if has_title is false, but has_content_1 is true only the content in has_content_1 should be shown.
At the moment, if one of the conditions returns false, none of the elements are displayed.