Product Types
Queries listed here are used to send requests to the Store Product Type API Routes.
Product types are string values that can be used to filter products by. Products can have more than one tag, and products can share types.
Queries
useProductTypes
This hook retrieves a list of product types. The product types can be filtered by fields such as value
or q
passed
in the query
parameter. The product types can also be sorted or paginated.
Example
To list product types:
import React from "react"
import { useProductTypes } from "medusa-react"
function Types() {
const {
product_types,
isLoading,
} = useProductTypes()
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Types</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Types
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 { useProductTypes } from "medusa-react"
function Types() {
const {
product_types,
limit,
offset,
isLoading,
} = useProductTypes({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{product_types && !product_types.length && (
<span>No Product Types</span>
)}
{product_types && product_types.length > 0 && (
<ul>
{product_types.map(
(type) => (
<li key={type.id}>{type.value}</li>
)
)}
</ul>
)}
</div>
)
}
export default Types
Hook Parameters
Filters and pagination configurations to apply on retrieved product types.
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 types details.
Was this section helpful?