039_生命周期(旧)_setState流程
class Count extends React.Component {
constructor(props) {
console.log("count-constructor");
super(props);
this.state = {count: 0}
}
add = () => {
const {count} = this.state;
this.setState({count: count + 1})
};
death = () => {
ReactDOM.unmountComponentAtNode(document.getElementById("test"))
}
componentWillMount() {
console.log("componentWillMount");
}
componentDidMount() {
console.log("componentDitMount")
}
shouldComponentUpdate() {
console.log("shouldComponentUpdate")
return true;
}
componentWillUpdate() {
console.log("componentWillUpdate");
}
componentDidUpdate() {
console.log("componentDidUpdate");
}
render() {
console.log("render")
const {count} = this.state;
return (
<div>
<h2>当前求和为:{count}</h2>
<button onClick={this.add}>点我+1</button>
<button onClick={this.death}>西在</button>
</div>
)
}
}
ReactDOM.render(<Count/>, document.getElementById('test'))