1. 程式人生 > >React 生命週期

React 生命週期

生命週期

  • Mounting 掛載 (渲染到DOM中)

- constructor

- componentWillMount 元件即將掛載

- render

- componentDidMount 元件完成掛載

  • Updating 更新

- componentWillReceiveProps(newPorps) 父元件更新,接收到父元件傳遞過來的新的props

- shouldComponentUpdate(newPorps,newState) return true|false 是否更新

- componentWillUpdate(newProps,newState) 即將更新元件

- render()

- componentDidUpdate() 更新完成

  • Unmounting 解除安裝 (從DOM中刪除)

- componentWillUnmount() 即將解除安裝