Skip to content

Instantly share code, notes, and snippets.

@alecguintu
Last active August 29, 2015 14:20
Show Gist options
  • Save alecguintu/fdb8445294f0dada8c50 to your computer and use it in GitHub Desktop.
Save alecguintu/fdb8445294f0dada8c50 to your computer and use it in GitHub Desktop.
Showing and hiding child components
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