react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
38 lines • 1 kB
JavaScript
import { createElement } from "react";
const renderReactElement = (element) => {
if (typeof element === "string") {
return element;
}
const convertChildrenAsArray = (element2) => {
if (element2?.props && typeof element2.props.children === "object") {
const childrenResult = [];
const { children } = element2.props;
Object.keys(children ?? {}).forEach((key) => {
childrenResult.push(
renderReactElement((children ?? {})[key])
);
});
return {
...element2,
props: { ...element2.props, children: childrenResult }
};
}
return {
...element2,
props: { ...element2.props, children: element2.props?.children ?? [] }
};
};
const fixedElement = convertChildrenAsArray(
element
);
const { type, props } = fixedElement;
return createElement(
type ?? "span",
props,
...props.children
);
};
export {
renderReactElement
};
//# sourceMappingURL=renderReactElement.mjs.map