react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
43 lines (40 loc) • 1.34 kB
JavaScript
'use client';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
const require_getIntlayer = require('../getIntlayer.cjs');
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
let react = require("react");
//#region src/client/useIntlayer.ts
/**
* Client-side hook that picks one dictionary by its key and returns its content.
*
* If the locale is not provided, it will use the locale from the client context.
*
* @param key - The unique key of the dictionary to retrieve.
* @param locale - Optional locale to override the current context locale.
* @returns The dictionary content for the specified locale.
*
* @example
* ```tsx
* import { useIntlayer } from 'react-intlayer';
*
* const MyComponent = () => {
* const content = useIntlayer('my-dictionary-key');
*
* return <div>{content.myField.value}</div>;
* };
* ```
*/
const useIntlayer = (key, locale) => {
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
return (0, react.useMemo)(() => {
return require_getIntlayer.getIntlayer(key, locale ?? currentLocale);
}, [
key,
currentLocale,
locale
]);
};
//#endregion
exports.useIntlayer = useIntlayer;
//# sourceMappingURL=useIntlayer.cjs.map