Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Kamilnaja
Last active January 23, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kamilnaja/ff2a4a1679e7ffdf28d44dac38298a5a to your computer and use it in GitHub Desktop.
Save Kamilnaja/ff2a4a1679e7ffdf28d44dac38298a5a 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