react 生命周期

生命周期componentWillMount()

//在组件即将被挂载到页面的时候自动执行componentDidMount()

//在组件被挂载到页面之后,自动被执行shouldComponentUpdate(nextProps,nextState){

//组件被更新之前自动被执行,默认返回true

if(nextState.count !== this.state.count){ 

  return true //可以渲染

  }

return false // 不可以渲染}

// shouldComponentUpdate 返回true则执行,返回false不执行componentWillUpdate()

//在组件被更新之前,自动执行componentDidUpdate()

//在组件更新完成之后,自动执行componentWillReceiveProps()

//一个组件要冲父组件接受参数

//只要父组件的render函数被重新执行了,子组件的这个生命周期函数就会被执行componentWillUnmount()

//当这个组件即将被从页面中剔除的时候会被执行

挂载时:

先执行构造器(constructor)

组件将要挂载(componentWillMount)

组件挂载渲染(render)

组件挂载完成(componentDidMount)

组件销毁(componentWillUnmount)

组件内部状态更新:

组件是否应该更新(shouldComponentUpdate)

组件将要更新(componentWillUpdate)

组件更新渲染(render)

组件更新完成(componentDidUpdate)

父组件重新 render:

调用组件将要接收新 props(componentWillReceiveProps)

组件是否应该更新(shouldComponentUpdate)

组件将要更新(componentWillUpdate)

组件更新渲染(render)

组件更新完成(componentDidUpdate)注:只有在父组件状态发生改变了,重新调用 render 时才会调用子组件的 componentWillReceiveProps 函数,父组件第一次引用子组件不会调用

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容