I'm trying to understand when componentWillUnmount is called. I have this class-based component:
class ClassComponent extends React.Component {
constructor(props) {
super(props);
this.state = { date: new Date().toLocaleString() };
}
componentDidMount() {
console.log('mounted');
}
componentWillUnmount() {
console.log('unmounting');
}
render() {
return <div></div>;
}
}
export default ClassComponent;
But when I check the console, it already prints "unmounting" although the component is still mounted. In total I have three logs in the console:
mounted unmounting mounted
Can someone explain to me why that is the case?