Skip to main content

FunctionSettings

FunctionSettings should be used when configuring the metafield configuration of a Shopify Function. It provides a structure for various input fields and controls, such as text fields, checkboxes, and selections. It also integrates with the native Contextual Save Bar to handle form submission and reset actions.

Learn more about registering events.

<typeof tagName> | null

A callback that is run when the form is reset.

<typeof tagName> | null

A callback that is run when the form is submitted.

Was this section helpful?

jsx

import {render} from 'preact';
import {useState} from 'preact/hooks';

export default async () => {
render(<Extension />, document.body);
};

function Extension() {
const [percentage, setPercentage] = useState(
shopify.data.metafields[0].value,
);

async function applyExtensionMetafieldChange() {
await shopify.applyMetafieldChange({
type: 'updateMetafield',
namespace: '$app:discounts-percentage',
key: 'function-configuration',
value: percentage,
valueType: 'integer',
});
}

return (
<s-function-settings
onSubmit={(e) => e.waitUntil(applyExtensionMetafieldChange())}
onReset={resetForm}
>
<s-number-field
step="1"
suffix="%"
label="Percentage"
name="percentage"
value={shopify.data.metafields[0].value}
onChange={(event) => setPercentage(event.currentTarget.value)}
/>
</s-function-settings>
);
}