Sales Channel Hooks - Admin Components
The sales channel hooks retrieve sales channels from the Medusa backend and manage the products linked to a sales channel.
import {
salesChannelsQueryKeys,
useSalesChannel,
useSalesChannelAddProducts,
useSalesChannelRemoveProducts,
useSalesChannels,
} from "@medusajs/dashboard/hooks"
These hooks are built on TanStack Query. Use them in your widgets and UI routes.
useSalesChannel#
Retrieve a single sales channel by its ID. The hook returns the sales channel along with the TanStack Query result properties.
Parameters#
Returns
Along with the following, the hook returns the rest of TanStack Query's useQuery result.
useSalesChannels#
Retrieve a paginated list of sales channels. Pass query parameters to filter or paginate the returned sales channels.
Parameters#
Returns#
Along with the following, the hook returns the rest of TanStack Query's useQuery result.
useSalesChannelAddProducts#
Add products to a sales channel. Pass the sales channel's ID to the hook, then pass an array of product IDs to mutate or mutateAsync.
const { mutate } = useSalesChannelAddProducts("sc_123")
const handleAdd = () => {
mutate(["prod_123"])
}
Parameters
Returns#
Along with the following, the hook returns the rest of TanStack Query's useMutation result.
useSalesChannelRemoveProducts#
Remove products from a sales channel. It accepts the same parameters as useSalesChannelAddProducts, and the array passed to mutate holds the IDs of the products to remove.
const { mutate } = useSalesChannelRemoveProducts(
"sc_123"
)
const handleRemove = () => {
mutate(["prod_123"])
}
Parameters#
Returns#
Along with the following, the hook returns the rest of TanStack Query's useMutation result.
salesChannelsQueryKeys#
is the query key factory for sales channel queries. Use , , , , and to build the keys that the hooks above register.
Use it to invalidate cached sales channel data after a custom mutation:
import { useQueryClient } from "@tanstack/react-query"
import {
salesChannelsQueryKeys,
} from "@medusajs/dashboard/hooks"
const queryClient = useQueryClient()
queryClient.invalidateQueries({
queryKey: salesChannelsQueryKeys.detail("sc_123"),
})