"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:写作不易,如要转裁,请标明转载出处。

微信小程序:前端开发宝典

猜你想看
什么是 JSX ?
受控组件和非受控组件区别是啥?
如何在 ReactJS 的 Props上应用验证?
组件库如何做按需加载?
redux reducer为什么不能修改state?
useMemo & useCallback的作用是什么?
登录
注册
回顶部