Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- render() {
- const func = (node) => {
- React.Children.forEach(node.children, (childNode) => {
- if (childNode && childNode.props && typeof childNode.props.children === "object") {
- func(childNode.props);
- }
- else if (typeof childNode.props.children === "string"){
- console.log(childNode.props);
- }
- })
- }
- func(this.props);
- return <span>{ this.props.children }</span>;
- }
- class Hello extends React.Component {
- constructor() {
- super();
- this.state = {
- children: [
- <div>test</div>,
- <div>test2</div>
- ]
- };
- setTimeout(() => {
- this.setState({
- children: [
- <div>new!</div>,
- <div>changed!</div>
- ]
- });
- }, 2000);
- }
- render() {
- return <p>{this.state.children}</p>;
- }
- }
- ReactDOM.render(
- <Hello />,
- document.getElementById('container')
- );
- render() {
- const func = (children) => {
- React.Children.map(children, (childNode) => {
- if (typeof childNode.props.children === "string")
- return React.cloneElement(childNode, childNode.props, "something");
- return React.cloneElement(childNode, childNode.props, func(childNode.props.children));
- })
- }
- return <span>{ func(this.props.children) }</span>;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement