Sales Channel Hooks - Admin Components

Note: These hooks are available since Medusa v2.21.0.

The sales channel hooks retrieve sales channels from the Medusa backend and manage the products linked to a sales channel.

Code
1import {2  salesChannelsQueryKeys,3  useSalesChannel,4  useSalesChannelAddProducts,5  useSalesChannelRemoveProducts,6  useSalesChannels,7} 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.

Code
1const { sales_channel, isPending } = useSalesChannel(2  "sc_123"3)

Parameters#

Loading...

Returns#

Along with the following, the hook returns the rest of TanStack Query's useQuery result.

Loading...

useSalesChannels#

Retrieve a paginated list of sales channels. Pass query parameters to filter or paginate the returned sales channels.

Code
1const { sales_channels, count } = useSalesChannels({2  limit: 20,3})

Parameters#

Loading...

Returns#

Along with the following, the hook returns the rest of TanStack Query's useQuery result.

Loading...

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.

Code
1const { mutate } = useSalesChannelAddProducts("sc_123")2
3const handleAdd = () => {4  mutate(["prod_123"])5}

Parameters#

Loading...

Returns#

Along with the following, the hook returns the rest of TanStack Query's useMutation result.

Loading...

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.

Code
1const { mutate } = useSalesChannelRemoveProducts(2  "sc_123"3)4
5const handleRemove = () => {6  mutate(["prod_123"])7}

Parameters#

Loading...

Returns#

Along with the following, the hook returns the rest of TanStack Query's useMutation result.

Loading...

salesChannelsQueryKeys#

salesChannelsQueryKeys is the query key factory for sales channel queries. Use all, lists(), list(query), details(), and detail(id) to build the keys that the hooks above register.

Use it to invalidate cached sales channel data after a custom mutation:

Code
1import { useQueryClient } from "@tanstack/react-query"2import {3  salesChannelsQueryKeys,4} from "@medusajs/dashboard/hooks"5
6const queryClient = useQueryClient()7
8queryClient.invalidateQueries({9  queryKey: salesChannelsQueryKeys.detail("sc_123"),10})
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵