import * as React from 'react'; import type { Locale } from '.'; import type { LocaleContextProps } from './context'; import LocaleContext from './context'; import defaultLocaleData from './en_US'; export type LocaleComponentName = Exclude; const useLocale = ( componentName: C, defaultLocale?: Locale[C] | (() => Locale[C]), ): Locale[C] => { const antLocale = React.useContext(LocaleContext); return React.useMemo>(() => { const locale = defaultLocale || defaultLocaleData[componentName]; const localeFromContext = antLocale?.[componentName] ?? {}; return { ...(typeof locale === 'function' ? locale() : locale), ...(localeFromContext || {}), }; }, [componentName, defaultLocale, antLocale]); }; export default useLocale;