React has four built-in methods that gets called,
in this order, when mounting a component:
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
The render() method is required and will always be called, the
others are optional and will be called if you define them.
class App extends React.Component {
state = {
showUser: false
}
render() {
return (
<div>
{this.state.showUser && <User name="Brad" />}
<button onClick={() => this.setState({ showUser: true })}>
Show User
</button>
<button onClick={() => this.setState({ showUser: false })}>
Hide User
</button>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'))