UNPKG

react-intlayer

Version:

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

38 lines (35 loc) 1.5 kB
'use client'; import { ContentSelectorRenderer } from "./ContentSelectorWrapper.mjs"; import { createElement } from "react"; import { getContent } from "@intlayer/core"; import { useEditedContentActions } from "@intlayer/editor-react"; //#region src/editor/useEditedContentRenderer.tsx const useEditedContentRenderer = ({ dictionaryKey, keyPath, children }) => { const editedContentContext = useEditedContentActions(); if (editedContentContext) return editedContentContext.getEditedContentValue(dictionaryKey, keyPath) ?? children; return children; }; const EditedContentRenderer = (props) => { const content = useEditedContentRenderer(props); if (typeof content === "object") { const transformedEditedContent = getContent(content, props, props.locale); if (typeof transformedEditedContent !== "string") { console.error(`Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`); return /* @__PURE__ */ createElement(ContentSelectorRenderer, { ...props, key: props.children }, props.children); } return /* @__PURE__ */ createElement(ContentSelectorRenderer, { ...props, key: props.children }, transformedEditedContent); } return /* @__PURE__ */ createElement(ContentSelectorRenderer, { ...props, key: props.children }, content); }; //#endregion export { EditedContentRenderer, useEditedContentRenderer }; //# sourceMappingURL=useEditedContentRenderer.mjs.map