react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
22 lines (19 loc) • 953 B
JavaScript
'use client';
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
import { useDictionary } from "./useDictionary.mjs";
import { useContext, useMemo } from "react";
import configuration from "@intlayer/config/built";
//#region src/client/useDictionaryAsync.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 useDictionaryAsync = async (dictionaryPromise, locale) => {
const { locale: currentLocale } = useContext(IntlayerClientContext);
const localeTarget = useMemo(() => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale, [currentLocale, locale]);
return useDictionary(await useMemo(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]), localeTarget);
};
//#endregion
export { useDictionaryAsync };
//# sourceMappingURL=useDictionaryAsync.mjs.map