Customer Hooks - Admin Components

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

The customer hooks fetch customers and their addresses from the Medusa backend. Use them to show customer data in your admin customizations.

Code
1import {2  customersQueryKeys,3  useCustomer,4  useCustomerAddress,5  useCustomers,6  useListCustomerAddresses,7} from "@medusajs/dashboard/hooks"

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


useCustomers#

Fetches a paginated list of customers. Pass query parameters to filter, paginate, or select the fields of the returned customers.

Code
1const { customers, count, isPending } = useCustomers({2  limit: 20,3})

Parameters#

Loading...

Returns#

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

Loading...

useCustomer#

Fetches a single customer by ID.

Code
1const { customer, isPending } = useCustomer(customerId, {2  fields: "+groups.id",3})

Parameters#

Loading...

Returns#

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

Loading...

useListCustomerAddresses#

Fetches the list of addresses of a customer.

Code
1const { addresses, count } =2  useListCustomerAddresses(customerId)

Parameters#

Loading...

Returns#

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

Loading...

useCustomerAddress#

Fetches a single address of a customer.

Code
1const { address } = useCustomerAddress(2  customerId,3  addressId4)

Parameters#

Loading...

Returns#

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

Loading...

customersQueryKeys#

A TanStack Query key factory for customer queries. Use it to invalidate cached customer data after you change a customer.

It provides all, lists(), list(query), details(), and detail(id, query).

Code
1import { useQueryClient } from "@tanstack/react-query"2import {3  customersQueryKeys,4} from "@medusajs/dashboard/hooks"5
6const Widget = () => {7  const queryClient = useQueryClient()8
9  const refreshCustomer = (id: string) => {10    queryClient.invalidateQueries({11      queryKey: customersQueryKeys.detail(id),12    })13  }14
15  // ...16}
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
⇧↵