Address Utilities - Admin Components

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

The @medusajs/dashboard/lib subpath exports the utilities that the Medusa Admin uses to display and compare addresses. Use them in your admin extensions to show an order's or customer's address the same way the Medusa Admin does.

Code
1import {2  getFormattedAddress,3  getFormattedCountry,4  isSameAddress,5} from "@medusajs/dashboard/lib"

getFormattedAddress#

Returns an address as an array of lines, ordered the way the Medusa Admin displays them: the full name, the company, the two address lines, a combined city, province, and postal code line, and the country's display name. Render each item of the array on its own line.

Code
1import { getFormattedAddress } from "@medusajs/dashboard/lib"2
3const ShippingAddress = ({ order }) => {4  const lines = getFormattedAddress({5    address: order.shipping_address,6  })7
8  return (9    <div>10      {lines.map((line, index) => (11        <span key={index}>{line}</span>12      ))}13    </div>14  )15}

Parameters#

Loading...

Returns#

Returns a string[] of the address's lines. The array is empty when you don't pass an address.

Note: When the address has no country object, the utility resolves the country's display name from the country_code. If the code isn't a supported country, it falls back to the uppercase code.

getFormattedCountry#

Returns a country's display name from its ISO 2 code.

Code
1import { getFormattedCountry } from "@medusajs/dashboard/lib"2
3getFormattedCountry("us") // "United States"

Parameters#

Loading...

Returns#

Returns a string of the country's display name. It returns the passed code when the country isn't supported, and an empty string when you don't pass a code.


isSameAddress#

Returns whether two addresses hold the same values. It compares the first name, last name, both address lines, city, postal code, province, and country code. It ignores the company and phone.

Code
1import { isSameAddress } from "@medusajs/dashboard/lib"2
3const isSame = isSameAddress(4  order.shipping_address,5  order.billing_address6)

Parameters#

Loading...

Returns#

Returns a boolean that is true when the compared fields match. It returns false when either address is missing.

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
⇧↵