react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
40 lines (38 loc) • 1.3 kB
JavaScript
import { createElement } from "react";
//#region src/reactElement/renderReactElement.ts
const renderReactElement = (element) => {
if (typeof element === "string") return element;
const convertChildrenAsArray = (element$1) => {
if (element$1?.props && typeof element$1.props.children === "object") {
const childrenResult = [];
const { children } = element$1.props;
Object.keys(children ?? {}).forEach((key) => {
const childElement = renderReactElement(children?.[key]);
if (typeof childElement === "object" && childElement !== null && "type" in childElement) childrenResult.push(createElement(childElement.type, {
...childElement.props,
key
}, ...Array.isArray(childElement.props?.children) ? childElement.props.children : [childElement.props?.children]));
else childrenResult.push(childElement);
});
return {
...element$1,
props: {
...element$1.props,
children: childrenResult
}
};
}
return {
...element$1,
props: {
...element$1.props,
children: element$1.props?.children ?? []
}
};
};
const { type, props } = convertChildrenAsArray(element);
return createElement(type ?? "span", props, ...props.children);
};
//#endregion
export { renderReactElement };
//# sourceMappingURL=renderReactElement.mjs.map