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
code
stringRequiredThe currency's code.
Mutation Function Parameters
The details to update in the currency
Mutation Function Returned Data
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
limit
numberRequiredThe maximum number of items that can be returned in the list.
offset
numberRequiredThe number of items skipped before the returned items in the list.
count
numberRequiredThe total number of items available.
An array of currency details.
Was this section helpful?