Product Collections
Queries and Mutations listed here are used to send requests to the Admin Product Collection API Routes.
All hooks listed require user authentication.
A product collection is used to organize products for different purposes such as marketing or discount purposes. For example, you can create a Summer Collection.
Mutations
useAdminCreateCollection
This hook creates a product collection.
Example
import React from "react"
import { useAdminCreateCollection } from "medusa-react"
const CreateCollection = () => {
const createCollection = useAdminCreateCollection()
// ...
const handleCreate = (title: string) => {
createCollection.mutate({
title
}, {
onSuccess: ({ collection }) => {
console.log(collection.id)
}
})
}
// ...
}
export default CreateCollection
Mutation Function Parameters
The product collection's details.
Mutation Function Returned Data
The collection's details.
useAdminUpdateCollection
This hook updates a product collection's details.
Example
import React from "react"
import { useAdminUpdateCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const updateCollection = useAdminUpdateCollection(collectionId)
// ...
const handleUpdate = (title: string) => {
updateCollection.mutate({
title
}, {
onSuccess: ({ collection }) => {
console.log(collection.id)
}
})
}
// ...
}
export default Collection
Hook Parameters
id
stringRequiredThe product collection's ID.
Mutation Function Parameters
The product collection's details to update.
Mutation Function Returned Data
The collection's details.
useAdminDeleteCollection
This hook deletes a product collection. This does not delete associated products.
Example
import React from "react"
import { useAdminDeleteCollection } from "medusa-react"
type Props = {
collectionId: string
}
const Collection = ({ collectionId }: Props) => {
const deleteCollection = useAdminDeleteCollection(collectionId)
// ...
const handleDelete = (title: string) => {
deleteCollection.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default Collection
Hook Parameters
id
stringRequiredThe product collection's ID.
Mutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.