Customer Hooks - Admin Components
The customer hooks fetch customers and their addresses from the Medusa backend. Use them to show customer data in your admin customizations.
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.
Parameters#
Returns
Along with the following, the hook returns the rest of TanStack Query's useQuery result.
useCustomer#
Fetches a single customer by ID.
Parameters#
Returns#
Along with the following, the hook returns the rest of TanStack Query's useQuery result.
useListCustomerAddresses#
Fetches the list of addresses of a customer.
Parameters
Returns#
Along with the following, the hook returns the rest of TanStack Query's useQuery result.
useCustomerAddress#
Fetches a single address of a customer.
Parameters#
Returns#
Along with the following, the hook returns the rest of TanStack Query's useQuery result.
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).
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}