了解一下react的一些钩子函数

挂载

  • construct()
  • static getDerivedStateFromProps()
  • render()
  • componentDidMount()

不建议使用:componentWillMount()

更新

  • static getDerivedStateFromProps()
  • shouldComponentUpdate()
  • render()
  • getSnapshotBeforeUpdate()
  • componentDidUpdate()

不建议使用:componentWillUpdate()、componentWillReceiveProps()

卸载

  • componentWillUnmount

错误处理

  • static getDerivedStateFromError()
  • componentDidCatch()

其他APIs

  • setState()
  • forceUpdate()

class属性

  • defaultProps
  • displayName

实例属性

  • props
  • state

猜你喜欢

转载自www.cnblogs.com/let423/p/11973876.html