Created
June 21, 2017 09:27
-
-
Save shubhang93/deff6bb52e68b191ccde2ad898594fa8 to your computer and use it in GitHub Desktop.
rwmQWg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="root"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReactChildrenExample extends React.Component { | |
constructor(props) { | |
super(props) | |
this.childrenPassedAsProps = this.props.children | |
} | |
render() { | |
let childrenWithProps = React.Children.map(this.childrenPassedAsProps, child => React.cloneElement(child, { | |
prefix: "ChildNode" | |
})) | |
return( | |
<div> | |
{childrenWithProps} | |
</div> | |
) | |
} | |
} | |
var ChildNode = props => | |
<p>{props.prefix + props.children}</p> | |
var App = props => | |
props.list.map(num => <ChildNode></ChildNode>) | |
var root = document.getElementById('root') | |
ReactDOM.render(<App/>,root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment