"React 的生命周期方法有哪些?"

React 的生命周期方法有哪些?

挂载/卸载过程

  • constructor()
  • componentWillMount()
  • componentDidMount()
  • componentWillUnmount ()

更新过程

  • componentWillReceiveProps (nextProps)
  • shouldComponentUpdate(nextProps,nextState)
  • componentWillUpdate (nextProps,nextState)
  • componentDidUpdate(prevProps,prevState)
  • render()

新增

  • getDerivedStateFromProps(nextProps, prevState) 代替:componentWillReceiveProps()
  • getSnapshotBeforeUpdate(prevProps, prevState) 代替:componentWillUpdate()

参考链接:

PS:写作不易,如要转裁,请标明转载出处。
登录
注册
回顶部