UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

28 lines (25 loc) 819 B
'use client'; import { IntlayerClientContext } from "./IntlayerProvider.mjs"; import { getIntlayer } from "../getIntlayer.mjs"; import { useContext, useMemo } from "react"; //#region src/client/useIntlayer.ts /** * On the client side, Hook that picking one dictionary by its key and return the content * * If the locale is not provided, it will use the locale from the client context * * When you need the raw string for attributes like `aria-label`, access the `.value` property of the returned content */ const useIntlayer = (key, locale) => { const { locale: currentLocale } = useContext(IntlayerClientContext); return useMemo(() => { return getIntlayer(key, locale ?? currentLocale); }, [ key, currentLocale, locale ]); }; //#endregion export { useIntlayer }; //# sourceMappingURL=useIntlayer.mjs.map