, React. JSX, , . React DOM.
JavaScript, , React.cloneElement. , this.props.children, :
render() {
const func = (children) => {
return React.Children.map(children, (childNode) => {
if (typeof childNode === "string")
return "something"; // cover case: <div>text<div></div></div>
if (typeof childNode.props.children === "string")
return React.cloneElement(childNode, [], "something");
return React.cloneElement(childNode, [], func(childNode.props.children));
})
}
return <span>{ func(this.props.children) }</span>;
}