React生命周期函数

我是研究僧i 提交于 2019-12-04 03:47:30

 

 

 

 

 

export default  class ClickS extends React.Component {
  constructor (props) {
    super(props)
    this.state= {
      msg: '123'
    }
    console.log(this.props)
    console.log('挂在前')
  }
  // componentWillMount // 这个生命周期函数,现在已经被废弃
  static getDerivedStateFromProps () {
    console.log('挂在前')
    return null
  }
  shouldComponentUpdate (nextProps,nextStates) {
    // 可以用来优化render
  }
  componentWillUpdate () {
    // 函数在shouldComponentUpdate之后render之前执行
  }
  componentDidUpdate () {
    // 函数在更新完毕之后执行
  }
  componentWillUnmount () {
    // 函数在组件删除之前执行
  }
  componentWillReceiveProps () {
    // 组件第一次存在于dom中,函数不会渲染
    // 如果已存在于dom中,函数才会被执行
  }
  componentDidMount () {
    console.log('挂载完毕')
  }
  render () {
    console.log('挂载')
    return <div></div>
  }
}

  

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!