Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.