美文网首页
2018-08-29 RN组件的生命周期

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

作者: 6seaq | 来源:发表于2018-08-29 10:06 被阅读14次
图片

挂载

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()

相关文章

网友评论

      本文标题:2018-08-29 RN组件的生命周期

      本文链接:https://www.haomeiwen.com/subject/rfkhwftx.html