Product Tags
Queries listed here are used to send requests to the Store Product Tag API Routes.
Product tags are string values that can be used to filter products by. Products can have more than one tag, and products can share tags.
Queries
useProductTags
This hook retrieves a list of product tags. The product tags can be filtered by fields such as id
or q
passed in the query
parameter. The product tags can also be sorted or paginated.
Example
To list product tags:
import React from "react"
import { useProductTags } from "medusa-react"
function Tags() {
const {
product_tags,
isLoading,
} = useProductTags()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Tags
By default, only the first 20
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import React from "react"
import { useProductTags } from "medusa-react"
function Tags() {
const {
product_tags,
limit,
offset,
isLoading,
} = useProductTags({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_tags && !product_tags.length && (
<span>No Product Tags</span>
)}
{product_tags && product_tags.length > 0 && (
<ul>
{product_tags.map(
(tag) => (
<li key={tag.id}>{tag.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Tags
Hook Parameters
Filters and pagination configurations to apply on the retrieved product tags.
Query Returned Data
limit
numberRequiredThe maximum number of items that can be returned in the list.
offset
numberRequiredThe number of items skipped before the returned items in the list.
count
numberRequiredThe total number of items available.
An array of product tags details.
Was this section helpful?