Shipping Option Hooks - Admin Components

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

The shipping option hooks retrieve shipping options from the Medusa backend, either a single option by ID or a paginated list.

Code
1import {2  shippingOptionsQueryKeys,3  useShippingOption,4  useShippingOptions,5} from "@medusajs/dashboard/hooks"

These hooks are built on TanStack Query. Use them in your widgets and UI routes.


useShippingOption#

Retrieve a single shipping option by its ID. Pass a query object as the second parameter to select the fields and relations to retrieve.

Code
1const { shipping_option, isPending } = useShippingOption(2  "so_123"3)

Parameters#

Loading...
Note: The query key of this hook only includes the shipping option's ID. If you use different query values for the same ID, set a custom queryKey through a separate query instead.

Returns#

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

Loading...

useShippingOptions#

Retrieve a paginated list of shipping options. Pass query parameters to filter the shipping options, for example by stock location or shipping profile.

Code
1const { shipping_options, count } = useShippingOptions({2  limit: 20,3})

Parameters#

Loading...

Returns#

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

Loading...

shippingOptionsQueryKeys#

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

Use it to invalidate cached shipping option data after a custom mutation:

Code
1import { useQueryClient } from "@tanstack/react-query"2import {3  shippingOptionsQueryKeys,4} from "@medusajs/dashboard/hooks"5
6const queryClient = useQueryClient()7
8queryClient.invalidateQueries({9  queryKey: shippingOptionsQueryKeys.all,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
⇧↵