state = {
showUserComponent: true
};
removeUserHandler = () => {
this.setState({showUserComponent: false});
}
render() {
return (
<div>
{this.state.showUserComponent ? <User /> : null}
<button onClick={this.removeUserHandler}>Remove User Component</button>
</div>
);
}
componentWillUnmount() {
// component is about to get removed => perform any cleanup work here!
console.log('I\'m about to be removed!');
}