react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
26 lines (23 loc) • 723 B
JavaScript
'use client';
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
import { getDictionary } from "../getDictionary.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,
currentLocale,
locale
]);
};
//#endregion
export { useDictionary };
//# sourceMappingURL=useDictionary.mjs.map