减轻state 只存储更组件渲染相关的数据(count/列表数据/loading等)

注意:不用做渲染的数据不要放在state中 比如定时器id等

对于这种需要在多个方法用到的数据 应该放在this中

 

//导入react
import React from 'react'
import ReactDOM from 'react-dom'

//导入组件
// 约定1:类组件必须以大写字母开头
// 约定2:类组件应该继承react.component父类 从中可以使用父类的方法和属性
// 约定3:组件必须提供render方法
// 约定4:render方法必须有返回值

class App extends React.Component {
constructor(props) {
super(props)
console.log('生命周期钩子函数:construtor')
}
componentDidMount=()=>{
this.timeId=setInterval(()=>{

},2000)
}
componentWillUnmount(){
clearInterval(this.timeId)
}
render() {
console.log('生命周期钩子函数:render')
console.log(this.props,"props")
return (
<div id="title">

</div>
)
}
}



ReactDOM.render(<App></App>, document.getElementById('root'))