React生命周期大总结

142 阅读1分钟

React生命周期大总结

  1. getDefaultProps,通过这个方法初始化props属性,props来自于父组件,以及其他组件
  2. getInitialState,初始化当前组件的状态,这个状态会贯穿整个项目,数据变化都取决于setState
  3. componentWillMount,在组件加载和初始化之前调用
  4. render ,react中最重要的方法,react元素的渲染都取决于render
  5. componentDidMount,react DOM加载完会调用这个方法
  6. componentWillReceiveProps,来自父组件属性的传递调用的方法
  7. shouldComponentUpdate,组件的更新,只要调用setState就会调用这个生命周期钩子
  8. componentWillUpdate,组件更新之前调用的方法
  9. componentDidUpdate ,组件更新之后调用的方法
  10. componentWillUnmount,组件销毁调用的方法

image.png