Skip to content

Instantly share code, notes, and snippets.

@RAAbbott
Created April 17, 2023 03:36
Show Gist options
  • Save RAAbbott/24f10ebaf90c76c571501af3a820328a to your computer and use it in GitHub Desktop.
Save RAAbbott/24f10ebaf90c76c571501af3a820328a to your computer and use it in GitHub Desktop.
Code for `index.jsx` file for your Checkout UI Extension used in my video here: https://youtu.be/FDLoz__VKVk
import React from "react";
import {
render,
BlockStack,
InlineStack,
Text,
View,
Image,
Heading,
useAppMetafields,
} from "@shopify/checkout-ui-extensions-react";
render("Checkout::Dynamic::Render", () => <App />);
function App() {
const metafields = useAppMetafields({
type: "shop",
key: "review",
namespace: "featured-review",
});
const featuredReview = metafields.length
? JSON.parse(metafields[0]?.metafield?.value)
: null;
if (featuredReview) {
return (
<BlockStack>
<Heading>What customers are saying</Heading>
<BlockStack
border="base"
padding="loose"
spacing="tight"
borderRadius="large"
>
<InlineStack blockAlignment="center" spacing="tight">
<Heading level="3">{featuredReview.customerName}</Heading>
<View maxInlineSize="15%" padding="extraTight">
<Image
fit="contain"
source="https://res.cloudinary.com/dci7ukl75/image/upload/v1680446609/istockphoto-1140391316-612x612_vlgprt.png"
/>
</View>
</InlineStack>
<Text>{featuredReview.reviewText}</Text>
</BlockStack>
</BlockStack>
);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment