这是应用程序类。返回一个 div 或 null 作为渲染函数中的 value 值。应用程序的componentWillUnmount函数不应该在返回null时也执行吗?我不明白只执行了 Header 和 Body 类的 componentWillUnmount 函数。
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {value : true};
}
componentWillUnmount() {
console.log('App componentWillUnmount');
}
btnClick() {
this.setState({
value: ! this.state.value
});
}
render () {
if(this.state.value) {
return (
<div>
<button onClick={this.btnClick.bind(this)}>Btn</button>
<Header id={this.state.value}></Header>
<Body></Body>
</div>
)
} else {
return null;
}
}
}
ReactDOM.render(
<App id="3"/>,
document.getElementById('root')
);