Custom
This class is used to send requests custom API Routes. All its method
are available in the JS Client under the medusa.admin.custom
property.
Mutations
useAdminCustomDelete
This hook sends a DELETE
request to a custom API Route.
Example
import React from "react"
import { useAdminCustomDelete } from "medusa-react"
type Props = {
customId: string
}
const Custom = ({ customId }: Props) => {
const customDelete = useAdminCustomDelete(
`/blog/posts/${customId}`,
["posts"]
)
// ...
const handleAction = (title: string) => {
customDelete.mutate(void 0, {
onSuccess: () => {
// Delete action successful
}
})
}
// ...
}
export default Custom
Type Parameters
TResponse
objectRequiredThe response's type which defaults to
any
.Hook Parameters
path
stringRequiredThe path to the custom endpoint.
queryKey
QueryKeyRequiredA list of query keys, used to invalidate data.
relatedDomains
RelatedDomainsA list of related domains that should be invalidated and refetch when the mutation
function is invoked.
Mutation Function Returned Data
TResponse
TResponseRequiredThe response based on the type provided for
useAdminCustomPost
This hook sends a POST
request to a custom API Route.
Example
import React from "react"
import { useAdminCustomPost } from "medusa-react"
import Post from "./models/Post"
type PostRequest = {
title: string
}
type PostResponse = {
post: Post
}
const Custom = () => {
const customPost = useAdminCustomPost
<PostRequest, PostResponse>(
"/blog/posts",
["posts"]
)
// ...
const handleAction = (title: string) => {
customPost.mutate({
title
}, {
onSuccess: ({ post }) => {
console.log(post)
}
})
}
// ...
}
export default Custom
Type Parameters
TPayload
Record<string, any>RequiredThe type of accepted body parameters which defaults to
Record<string, any>
.TResponse
objectRequiredThe type of response, which defaults to
any
.Hook Parameters
path
stringRequiredThe path to the custom endpoint.
queryKey
QueryKeyRequiredA list of query keys, used to invalidate data.
relatedDomains
RelatedDomainsA list of related domains that should be invalidated and refetch when the mutation
function is invoked.
Mutation Function Parameters
TPayload
TPayloadRequiredThe payload based on the specified type for
Mutation Function Returned Data
TResponse
TResponseRequiredThe response based on the specified type for