Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Is it possible to split a component file in Checkout UI Extention?

Solved

Is it possible to split a component file in Checkout UI Extention?

Monesynth
Shopify Partner
2 1 0

Hi, I'm new to develop Checkout UI Extension.

Is it possible to split JSX components from 'Checkout.jsx' file by creating own custom directories and files like this.

 

スクリーンショット 2023-12-24 18.08.09.png

 

In Checkout.jsx:

 

 

import { reactExtension } from "@shopify/ui-extensions-react/checkout";
import { ShippingOptions } from "./components/ShippingOptions"; // <= 🆕 This is what I created.

const shippingOptionListAfterRneder = reactExtension(
"purchase.checkout.shipping-option-list.render-after",
() => <ShippingOptions />
);
export { shippingOptionListAfterRneder };

 

 

 

I created '/components/' directory in '/src' directory. and put own 'ShippingOptions' component file in it. Then I import that component from 'Checkout.jsx'. but the Shopify CLI says the following:

 

スクリーンショット 2023-12-24 18.26.58.png

 

shopify.extension.toml:

api_version = "2023-10"

[capabilities]
api_access = true
network_access = true
block_progress = true

[[extensions]]
type = "ui_extension"
name = "checkout-ui"
handle = "checkout-ui"

# [START order-status.config-extension]
[[extensions.targeting]]
target = "purchase.checkout.shipping-option-list.render-after"
module = "./src/Checkout.jsx"
export = "shippingOptionListAfterRneder"

 

I wanted to split jsx components from main module, because that file might be so fat, but it's not possible?

Accepted Solution (1)

Monesynth
Shopify Partner
2 1 0

This is an accepted solution.

It's been solved, this is just a js typo problem, I created 'ShippingOptions.jsx', but 'ShippingOptions.js' is right. I renamed it, and it works!

View solution in original post

Replies 6 (6)

Monesynth
Shopify Partner
2 1 0

This is an accepted solution.

It's been solved, this is just a js typo problem, I created 'ShippingOptions.jsx', but 'ShippingOptions.js' is right. I renamed it, and it works!

Liam
Community Manager
3108 344 889

Glad you figured this out and thanks for coming back to post your solution!

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

Catalin_G
Shopify Partner
7 0 3

And why was that a "mistake/typo"? is there somewhere in the docs specified we should not use the jsx/tsx extension for nested components? I couldn't find anything related to it

suho
Shopify Partner
2 0 0

yes wondering the same? if anyone can reply to this?

Catalin_G
Shopify Partner
7 0 3

If you still want to use the jsx/tsx files, you will need to add the extension to files when importing them. Example:

You create a new component, `Example.jsx`
You import this component inside `Checkout.jsx` as `import Example from "./components/Example.jsx`

suho
Shopify Partner
2 0 0

yes thanks!