Skip to main content
Skip to main content

Currencies

Queries and Mutations listed here are used to send requests to the Admin Currency API Routes.

All hooks listed require user authentication.

A store can use unlimited currencies, and each region must be associated with at least one currency. Currencies are defined within the Medusa backend. The methods in this class allow admins to list and update currencies.

Related Guide: How to manage currencies.

Mutations

useAdminUpdateCurrency

This hook updates a currency's details.

Example

import React from "react"
import { useAdminUpdateCurrency } from "medusa-react"

type Props = {
currencyCode: string
}

const Currency = ({ currencyCode }: Props) => {
const updateCurrency = useAdminUpdateCurrency(currencyCode)
// ...

const handleUpdate = (includes_tax: boolean) => {
updateCurrency.mutate({
includes_tax,
}, {
onSuccess: ({ currency }) => {
console.log(currency)
}
})
}

// ...
}

export default Currency

Hook Parameters

codestringRequired
The currency's code.

Mutation Function Parameters

AdminPostCurrenciesCurrencyReqAdminPostCurrenciesCurrencyReqRequired
The details to update in the currency

Mutation Function Returned Data

AdminCurrenciesResAdminCurrenciesResRequired
A currency's details.

Queries

useAdminCurrencies

This hook retrieves a list of currencies. The currencies can be filtered by fields such as code. The currencies can also be sorted or paginated.

Example

To list currencies:

import React from "react"
import { useAdminCurrencies } from "medusa-react"

const Currencies = () => {
const { currencies, isLoading } = useAdminCurrencies()

return (
<div>
{isLoading && <span>Loading...</span>}
{currencies && !currencies.length && (
<span>No Currencies</span>
)}
{currencies && currencies.length > 0 && (
<ul>
{currencies.map((currency) => (
<li key={currency.code}>{currency.name}</li>
))}
</ul>
)}
</div>
)
}

export default Currencies

By default, only the first 20 records are retrieved. You can control pagination by specifying the limit and offset properties:

import React from "react"
import { useAdminCurrencies } from "medusa-react"

const Currencies = () => {
const { currencies, limit, offset, isLoading } = useAdminCurrencies({
limit: 10,
offset: 0
})

return (
<div>
{isLoading && <span>Loading...</span>}
{currencies && !currencies.length && (
<span>No Currencies</span>
)}
{currencies && currencies.length > 0 && (
<ul>
{currencies.map((currency) => (
<li key={currency.code}>{currency.name}</li>
))}
</ul>
)}
</div>
)
}

export default Currencies

Hook Parameters

Filters and pagination configurations to apply on retrieved currencies.

Query Returned Data

limitnumberRequired
The maximum number of items that can be returned in the list.
offsetnumberRequired
The number of items skipped before the returned items in the list.
countnumberRequired
The total number of items available.
currenciesCurrency[]Required
An array of currency details.
Was this section helpful?