react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
1 lines • 1.56 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { LocalesValues } from '@intlayer/config/client';\nimport type { DictionaryKeys } from '@intlayer/core';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n *\n * When you need the raw string for attributes like `aria-label`, access the `.value` property of the returned content\n */\nexport const useIntlayer = <T extends DictionaryKeys>(\n key: T,\n locale?: LocalesValues\n): DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content']> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget) as any;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";AAMA,SAAS,YAAY,eAAe;AACpC,SAAS,mBAAmB;AAE5B,SAAS,6BAA6B;AAS/B,MAAM,cAAc,CACzB,KACA,WACyE;AACzE,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAElE,SAAO,QAAQ,MAAM;AACnB,UAAM,eAAe,UAAU;AAE/B,WAAO,YAAY,KAAK,YAAY;AAAA,EACtC,GAAG,CAAC,KAAK,eAAe,MAAM,CAAC;AACjC;","names":[]}