Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joseworks/06eb985098761b84beb462185e65d053 to your computer and use it in GitHub Desktop.
Save Joseworks/06eb985098761b84beb462185e65d053 to your computer and use it in GitHub Desktop.
class Child extends React.Component {
render () {
return (<div>I'm the child</div>);
}
}
class ShowHide extends React.Component {
constructor () {
super ();
this.state = {
childVisible: false
}
}
render () {
return (
<div>
<div onClick={() => this.onClick()}>
Parent = click me to show/hide my child
</div>
{
this.state.childVisible
? <Child />
: null
}
</div>
)
}
onClick () {
this.setState({childVisible: !this.state.childVisible});
}
}
ReactDOM.render(
<ShowHide />,
document.getElementById('container')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment