Skip to main content
Glama
useNumber.ts1.06 kB
'use client'; import { number } from '@intlayer/core'; import { useCallback, useContext } from 'preact/hooks'; import { IntlayerClientContext } from '../IntlayerProvider'; /** * React client hook that provides a localized number formatter. * * Uses the current locale from {@link useLocaleBase} and returns * a function that can be used to format numbers consistently * according to the user's locale. * * @example * ```tsx * const formatNumber = useNumber(); * * formatNumber(12345); * // e.g. "12,345" (en-US) * // e.g. "12 345" (fr-FR) * * formatNumber(0.75, { style: "percent" }); * // e.g. "75%" * ``` * * @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string} * A number formatting function bound to the active locale. */ export const useNumber = () => { const { locale } = useContext(IntlayerClientContext); return useCallback( (...args: Parameters<typeof number>) => number(args[0], { ...args[1], locale: args[1]?.locale ?? locale, }), [locale] ); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server