use Metafieldhook
hook
Returns a single filtered Metafield
or undefined
.
Anchor to useMetafield-parametersParameters
- Anchor to filtersfiltersrequired
| undefined
UseMetafieldGeneratedType
Returns a single filtered `Metafield` or `undefined`.
- filters
MetafieldFilter
Metafield | undefined
export function useMetafield(filters: MetafieldFilter): Metafield | undefined {
const {namespace, key} = filters;
if (!namespace || !key) {
throw new CheckoutUIExtensionError(
'You must pass in both a namespace and key',
);
}
const metafields = useMetafields({namespace, key});
return metafields.length ? metafields[0] : undefined;
}
MetafieldFilter
- namespace
string
- key
string
interface MetafieldFilter {
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?