zoukankan      html  css  js  c++  java
  • react组件生命周期

    1. Mounting/组建挂载相关

      (1)componentWillMount

        组件将要挂载。在render之前执行,但仅执行一次,即使多次重复渲染该组件或者改变了组件的state

      (2)componentDidMount

        组件已经挂载。在render之后执行,同一个组件重复渲染只执行一次。

    2. Updating/组建更新相关

      (1)componentWillReceiveProps(object nextProps)

        已加载组件收到新的props之前调用,注意组件初始化渲染时则不会执行

      (2)shouldComponentUpdate(object nextProps, object nextState)

        组件判断是否重新渲染时调用。该接口实际是在组件接收到了新的props或者新的state的时候会立即调用

      (3)componentWillUpdate(object nextProps, object nextState)

        组件将要更新

      (4)componentDidUpdate(object nextProps, object nextState)

        组建已经更新

    3. Unmounting/组件移除相关

      (1)componentWillUnmount

        在组件要被移除之前的时间点触发,可以利用该方法来执行一些必要的清理

    4. 生命周期中与props和state相关

      (1)getDefaultProps  设置props属性默认值

      (2)getInitialState      设置state属性初始值  

  • 相关阅读:
    PHP之常用设计模式
    MySQL之慢查询日志和通用查询
    mysql之找回误删数据
    PHPer未来路在何方...
    如何成为更优秀的程序员
    常见的 CSRF、XSS、sql注入、DDOS流量攻击
    API接口TOKEN设计
    成为更好的程序员的八中途径
    奉秉格言
    PHP优化与提升
  • 原文地址:https://www.cnblogs.com/ImaY/p/9037383.html
Copyright © 2011-2022 走看看