Last active
August 29, 2015 14:20
-
-
Save alecguintu/fdb8445294f0dada8c50 to your computer and use it in GitHub Desktop.
Showing and hiding child components
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
Sample 1 | |
_click: function() { | |
if ($('#add-here').is(':empty')) | |
React.render(<Child />, $('#add-here')[0]); | |
else | |
React.unmountComponentAtNode($('#add-here')[0]); | |
}, | |
render: function() { | |
return( | |
<div> | |
<div onClick={this._click}>Parent - click me to add child</div> | |
<div id="parent-add"></div> | |
</div> | |
) | |
} | |
Sample 2 | |
getInitialState: function () { | |
return { showChild: false }; | |
}, | |
_click: function() { | |
this.setState({showChild: !this.state.showChild}); | |
}, | |
render: function() { | |
return( | |
<div> | |
<div onClick={this._click}>Parent - click me to add child</div> | |
{this.state.showChild ? <Child /> : null} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment