markdown 31 - 组件生命周期 - 更新

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 31 - 组件生命周期 - 更新相关的知识,希望对你有一定的参考价值。

- component lifecycle for updating
- have to differentiate between updates triggered by the parent (changing props) and internally triggered updates (changing state)
- here we'll be focusing on triggered by parent
- process:
  1. componentWillReceiveProps(nextProps) | DO: sync state to props | DON'T: cause side-effects
  2. shouldComponentUpdate(nextProps, nextState) | may cancel the updating process! | DO: decide whether to continue with the update or not | DON'T: cause side effects
  3. (if allowed to update) componentWillUpdate(nextProps, nextState) | DO: sync state to props | DON'T: cause side effects
  4. render() | prepare and structure your JSX code
  5. (if allowed to update) React will then update all child component props, may trigger update for child components
  6. (if allowed to update) componentDidUpdate() | DO: cause side effects | DON'T: update state (triggers re-render)

以上是关于markdown 31 - 组件生命周期 - 更新的主要内容,如果未能解决你的问题,请参考以下文章

react 组件的生命周期

React:组件的生命周期

React9.组件的生命周期

React9.组件的生命周期

React组件的生命周期

react生命周期剖析