React-Native 生命周期

React-Native 生命周期_第1张图片
01.png

实例化

=============

  • 组件类型首次**实例化时初始化默认props属性,多实例共享
getDefaultProps
  • 实例化时初始化默认state属性
getInitialState
  • 在渲染之前触发一次
componentWillMount
  • 渲染函数,返回DOM结构
render
  • 在渲染之后触发一次
componentDidMount

有需要重新渲染(props变更或者setState改变state时)


  • 组件接收到新的props时调用,并将其作为参数nextProps使用,可在此更改组件
componentWillReceiveProps
  • 判断是否需要更新组件(在首次渲染期间或者调用了forceUpdate方法后,该方法不会被调用)
shouldComponentUpdate
  • 更新渲染前调用
componentWillUpdate
  • 渲染函数,返回DOM结构
render
  • 更新渲染后调用
componentDidUpdate

你可能感兴趣的:(React-Native 生命周期)