React.Component

226 阅读1分钟
  • React的组件可以定义为class或函数的形式
  • 定义class组件,需要继承React.Component
  • class组件提供的功能更多

属性

displayName

defaultProps

props

state

方法

setState()

forceUpdate()

construtor()

static getDerivedStateFromProps()

render()

componentDidMount()

shouldComponentUpdate()

getSnapshotBeforeUpdate()

  • 类似vue的beforeUpdate

componentDidUpdate()

  • 类似vue的updated

componentWillUnmount()

  • 类似vue的destory()

static getDerivedStateFromError()

componentDidCatch()