use Metafieldshook
hook
Returns the current array of metafields
applied to the checkout.
You can optionally filter the list.
Anchor to useMetafields-parametersParameters
- Anchor to filtersfilters
[]
UseMetafieldsGeneratedType
Returns the current array of `metafields` applied to the checkout. You can optionally filter the list.
- filters
MetafieldsFilters
Metafield[]
export function useMetafields<
ID extends RenderExtensionPoint = RenderExtensionPoint,
>(filters?: MetafieldsFilters): Metafield[] {
const metaFields = useSubscription(useApi<ID>().metafields);
return useMemo(() => {
if (filters) {
const {namespace, key} = filters;
if (!namespace) {
throw new CheckoutUIExtensionError(
'You must pass in a namespace with a key',
);
}
const filteredResults = metaFields.filter(
(metafield) =>
metafield.namespace === namespace && (!key || metafield.key === key),
);
return filteredResults;
}
return metaFields;
}, [filters, metaFields]);
}
MetafieldsFilters
- namespace
string
- key
string
interface MetafieldsFilters {
namespace: string;
key?: string;
}
Metafield
Metadata associated with the checkout.
- key
The name of the metafield. It must be between 3 and 30 characters in length (inclusive).
string
- namespace
A container for a set of metafields. You need to define a custom namespace for your metafields to distinguish them from the metafields used by other apps. This must be between 2 and 20 characters in length (inclusive).
string
- value
The information to be stored as metadata.
string | number
- valueType
The metafield’s information type.
"string" | "integer" | "json_string"
export interface Metafield {
/**
* The name of the metafield. It must be between 3 and 30 characters in
* length (inclusive).
*/
key: string;
/**
* A container for a set of metafields. You need to define a custom
* namespace for your metafields to distinguish them from the metafields
* used by other apps. This must be between 2 and 20 characters in length (inclusive).
*/
namespace: string;
/**
* The information to be stored as metadata.
*/
value: string | number;
/** The metafield’s information type. */
valueType: 'integer' | 'string' | 'json_string';
}
Was this section helpful?