Skip to main content

useMoney

The useMoney hook takes a MoneyV2 object and returns a default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by Intl.NumberFormat.

The useMoney hook takes a MoneyV2 object from the Storefront API or a MoneyV2 object from the Customer Account API and returns a default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by Intl.NumberFormat. Uses locale from ShopifyProvider  

Anchor to money
money
required

Examples
import {useMoney, ShopifyProvider} from '@shopify/hydrogen-react';

export function App() {
return (
<ShopifyProvider languageIsoCode="EN" countryIsoCode="US">
<UsingMoney />
</ShopifyProvider>
);
}

function UsingMoney() {
const myMoney = {amount: '100', currencyCode: 'USD'};
const money = useMoney(myMoney);
return (
<>
<div>Localized money: {money.localizedString}</div>
<div>Money without trailing zeros: {money.withoutTrailingZeros}</div>
</>
);
}


Was this page helpful?