Honeycomb

use-currency-formatter

Since: ver.10.0.0 Implements predefined formats for Currency internationalization.

Props

Prop nameTypeDefaultDescription
codestring | undefinedEUR

The currency ISO code (e.g.: `EUR` for Euros, `USD` for United States Dollar).

display"symbol" | "narrowSymbol" | "code" | "name" | undefinedsymbol

The currency display format.

localeLocalesArgument

The locale for number formatting. Used for `Intl.NumberFormat` API.

intlFormatOptionsNumberFormatOptions | undefined

Options forwarded to Intl.NumberFormat API. Intl.NumberFormat

For most of the cases we strongly advice to use provided Currency component as it also allows for better visual and semantic consistency.


useCurrencyFormatter allows for more granular currency formatting as it returns a pre-configured formatter object. This is useful for performance optimizations or if you need access to more formatting methods like formatRange or formatToParts.

import { useCurrencyFormatter } from '@flixbus/honeycomb-react';

const PriceRange = ({ priceStart, priceEnd, locale }) => {
  const { formatter } = useCurrencyFormatter({ locale });
  return <p data-testid="formatter-output">{formatter.formatRange(priceStart, priceEnd)}</p>;
};

<>
  Ramen prices in the area vary between: <PriceRange priceStart={9} priceEnd={16} locale="de" />
</>