2018-08-29 RN组件的生命周期

图片

挂载

constructor

constructor(props) {
  super(props);
  this.state = {
    text: '构造方法'
  };
}

componentWillMount

componentWillMount()

render

  • 检查 this.props 和 this.state 的数据并返回一个 React 元素

componentDidMount

componentDidMount()

  • render方法后被执行

更新

  • 当一个组件被重新渲染时,会调用如下方法。

componentWillReceiveProps

componentWillReceiveProps(nextProps) //在挂载的组件接收到新的props时被调用

shouldComponentUpdate

boolean shouldComponentUpdate(nextProps, nextState) //当组件接收到新的props和state时, shouldComponentUpdate方法默认返回true

componentWillUpdate

componentWillUpdate(nextProps, nextState)

componentDidUpdate

componentDidUpdate(prevProps, prevState) //两个参数分别是渲染前的props和渲染前的state

卸载

componentWillUnmount()

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

相关阅读更多精彩内容

友情链接更多精彩内容