UNPKG

react-intlayer

Version:

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

26 lines (23 loc) 733 B
'use client'; import { getDictionary } from "../getDictionary.mjs"; import { IntlayerClientContext } from "./IntlayerProvider.mjs"; import { useContext, useMemo } from "react"; //#region src/client/useDictionary.ts /** * On the server side, Hook that transform a dictionary and return the content * * If the locale is not provided, it will use the locale from the client context */ const useDictionary = (dictionary, locale) => { const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {}; return useMemo(() => { return getDictionary(dictionary, locale ?? currentLocale); }, [ dictionary.key, currentLocale, locale ]); }; //#endregion export { useDictionary }; //# sourceMappingURL=useDictionary.mjs.map