@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
32 lines (28 loc) • 1 kB
JavaScript
"use client";
import { i18nCache } from "../../providers/i18n-provider/i18n-cache.js";
import { useI18n } from "../../providers/i18n-provider/i18n-provider.js";
import { useCallback, useRef } from "react";
//#region src/components/format/use-format-number.ts
const getFormatNumber = i18nCache(Intl.NumberFormat);
/**
* `useFormatNumber` is a custom hook that returns the formatted number.
*
* @see https://yamada-ui.com/docs/hooks/use-format-number
*/
const useFormatNumber = (value, options) => {
return useNumberFormat(options)(value);
};
const useNumberFormat = ({ locale,...options } = {}) => {
const { locale: defaultLocale } = useI18n();
const memoizedOptions = useRef(options);
locale ??= defaultLocale;
return useCallback((value, options$1) => {
return getFormatNumber(locale, {
...memoizedOptions.current,
...options$1
}).format(value);
}, [locale]);
};
//#endregion
export { getFormatNumber, useFormatNumber, useNumberFormat };
//# sourceMappingURL=use-format-number.js.map