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

2018-08-29  本文已影响14人  6seaq
图片

挂载

constructor

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

componentWillMount

componentWillMount()

render

componentDidMount

componentDidMount()

更新

componentWillReceiveProps

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

shouldComponentUpdate

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

componentWillUpdate

componentWillUpdate(nextProps, nextState)

componentDidUpdate

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

卸载

componentWillUnmount()

上一篇 下一篇

猜你喜欢

热点阅读