### Handling Click Events in Preact Admin Extension
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/index
This example demonstrates how to handle click events on a Shopify Admin UI extension button using Preact. It shows two methods: using the `onClick` prop directly in JSX and using `addEventListener` with a standard DOM element. Both methods achieve the same result of logging a message when the button is clicked.
```jsx
export default function HandlingEvents() {
const handleClick = () => {
console.log('s-button clicked');
};
return Click me;
}
```
```jsx
export default function HandlingEvents() {
const handleClick = () => {
console.log('s-button clicked');
};
const button = document.createElement('s-button');
button.addEventListener('click', handleClick);
document.body.appendChild(button);
}
```
--------------------------------
### Deploying Shopify Extensions using CLI
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/index
Provides instructions on how to deploy a Shopify app and its extensions using the Shopify CLI. It includes navigating to the app's directory and executing the deploy command.
```bash
# navigate to your app's root directory:
cd my-app
# deploy your app and its extensions:
shopify app deploy
# follow the steps to deploy
```
--------------------------------
### Selecting a Product with Resource Picker
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/index
Shows how to use the `shopify.resourcePicker` API to allow users to select a product from a search-based interface and receive the selected product data in the extension.
```javascript
import { render } from 'preact';
export default async () => {
render(, document.body);
}
function Extension() {
const handleSelectProduct = async () => {
const selected = await shopify.resourcePicker({ type: 'product' });
console.log(selected);
};
return Select product;
}
```
--------------------------------
### Product Details Configuration Extension
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/extension-targets
This extension target allows developers to render custom UI on the product details page. It enables configuration of product bundles and other product-specific settings.
```APIDOC
Target: admin.product-details.configuration.render
Description: Renders custom UI on the product details page for configuration purposes.
Appears On: Product details page
```
--------------------------------
### Shopify Admin Extension Target Implementation
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/extension-targets
This snippet shows the JavaScript implementation for registering admin UI extension targets. It assumes a `shopify.extension.toml` file has been configured to point to this module. The code would typically involve calling Shopify's extension API to register specific target locations.
```javascript
// admin_extension.js
// Assume Shopify's extension API is available globally or imported
// Example: Shopify.extend(extensionConfig);
const extensionConfig = {
// ... other extension configurations
// Example target registration:
// targets: [
// {
// name: "admin.product.details.block.render",
// module: "./components/ProductDetailsBlock"
// }
// ]
};
// Shopify.extend(extensionConfig);
```
--------------------------------
### Product Variant Details Configuration Extension
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/extension-targets
This extension target allows developers to render custom UI on the product variant details page. It facilitates the configuration of product bundles and variant-specific settings.
```APIDOC
Target: admin.product-variant-details.configuration.render
Description: Renders custom UI on the product variant details page for configuration purposes.
Appears On: Product variant details page
```
--------------------------------
### Preact Admin Extension with State
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/index
This code snippet shows a basic Admin UI extension scaffolded with Preact. It utilizes the `useState` hook from Preact to manage a counter and renders a text display and a button. Clicking the button increments the counter, demonstrating state management within the extension.
```jsx
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useState} from 'preact/hooks';
export default async () => {
render(, document.body);
}
function Extension() {
const [count, setCount] = useState(0);
return (
<>
Count: {count}
setCount(count + 1)}>
Increment
>
);
}
```
--------------------------------
### App Authentication with fetch()
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/network-features
Demonstrates how Admin UI extensions can make authenticated calls to your app's backend. When using `fetch()` to your app's auth domain, an `Authorization` header with a Shopify OpenID Connect ID Token is automatically added.
```javascript
import {render} from 'preact';
import {useEffect, useState} from 'preact/hooks';
export default async () => {
render(, document.body);
}
// Get product info from app backend
async function getProductInfo(id) {
const res = await fetch(`/api/products/${id}`);
return res.json();
}
function Extension() {
// Contextual "input" data passed to this extension:
const {data} = shopify;
const productId = data.selected?.[0]?.id;
const [productInfo, setProductInfo] = useState();
useEffect(() => {
getProductInfo(productId).then(setProductInfo);
}, [productId]);
return (
Info: {productInfo?.title}
);
}
```
--------------------------------
### Generate Shopify Admin Extension
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/index
This snippet demonstrates how to generate a new Shopify Admin UI extension using the Shopify CLI. It includes steps for initializing a new app if one doesn't exist and then generating the extension within the app's directory. Ensure you are using Shopify CLI version 3.80.0 or higher.
```bash
POLARIS_UNIFIED=true shopify app init --name my-app
cd my-app
POLARIS_UNIFIED=true shopify app generate extension
```
--------------------------------
### Shopify Admin Protocol Link
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/network-features
Constructs a URL to a specific product within the Shopify Admin using the `shopify:admin` protocol.
```html
Link to Product Page
```
--------------------------------
### Shopify Admin Extension Target Registration
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/extension-targets
This snippet demonstrates how to define and register targets for Shopify Admin UI extensions. Targets specify the locations within the Shopify admin where your extension will be visible. Registration involves configuring the `shopify.extension.toml` file and referencing the corresponding JavaScript module.
```toml
[extension]
# ... other configurations
module = "./admin_extension.js"
```
--------------------------------
### Direct Shopify Admin API Access
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/network-features
Shows how to make authenticated Shopify Admin GraphQL API requests directly from your extension using `fetch()`. These calls are handled directly by Shopify and are fast. Direct API requests use online access mode by default.
```javascript
import {render} from 'preact';
export default async () => {
const productId = shopify.data.selected?.[0]?.id;
const product = await getProduct(productId);
render(, document.body);
};
async function getProduct(id) {
const res = await fetch('shopify:admin/api/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
query GetProduct($id: ID!) {
product(id: $id) {
title
}
}
`,
variables: {id},
}),
});
const {data} = await res.json();
return data.product;
}
function Extension({product}) {
return (
The selected product title is {product.title}
);
}
```
--------------------------------
### Using Forms in Block Extensions
Source: https://shopify.dev/docs/api/admin-extensions/2025-10-rc/index
Demonstrates how to use the Form component in a Block extension to manage form state and interact with the resource page's contextual save bar. It covers handling input changes, form submission, and resetting dirty states based on default values.
```javascript
import { render } from 'preact';
import { useState } from 'preact/hooks';
export default async () => {
render(, document.body);
}
const defaultValues = {
text: 'default value',
number: 50,
};
function Extension() {
const [textValue, setTextValue] = useState('');
const [numberValue, setNumberValue] = useState('');
return (
{
event.waitUntil(fetch('app:save/data'));
console.log('submit', {textValue, numberValue});
}
onReset={() => console.log('automatically reset values')}
>
setTextValue(e.target.value)}
/>