zoukankan      html  css  js  c++  java
  • 说一说我了解的react生命周期函数

    我了解的几个阶段

    1. Mounting 挂载
    2. Updating 更新
    3. Unmounting 卸载

    我说几个我常用的钩子函数

    1.挂载阶段Mounting 

      1)constructor():函数构造器

          执行次数:1

          作用:初始化

      2)componentDidmount()

          执行次数:1

          作用:Dom挂载完成获取节点,通常在这里发起数据请求

      3)render()

          react最重要的步骤,创建虚拟dom,进行diff算法,更新dom树都在此进行。此时就不能更改state了。

      4)shouldComponentUpdate(nextProps, nextState):判断组件是否更新的钩子函数

          执行次数:多次
          触发条件:组件挂载之后,每次调用setState后都会调用shouldComponentUpdate判断是否需要重新渲染组件。默认返回true,需要重新render。

    2.更新阶段Updating

      1)componentDidUpdate(prevProps, prevState):组件完成更新时执行的钩子函数

        执行次数:多次

        作用:除了首次render之后调用componentDidMount,其它render结束之后都是调用componentDidUpdate。

    3.卸载阶段Unmounting

      1)componentWillUnmount():组件将要卸载是执行的钩子函数

        执行次数:1

        触发条件:组件将要被卸载的时候调用。一般在componentDidMount里面注册的事件需要在这里删除

    知道的并不是很多,所有就写了这些

  • 相关阅读:
    MVC ORM 架构
    Kubernetes 第八章 Pod 控制器
    Kubernetes 第七章 Configure Liveness and Readiness Probes
    Kubernetes 第六章 pod 资源对象
    Kubernetes 第五章 YAML
    Kubernetes 核心组件
    Kubernetes 架构原理
    Kubernetes 第四章 kubectl
    Kubernetes 第三章 kubeadm
    yum 配置及yum 源配置
  • 原文地址:https://www.cnblogs.com/qdjj/p/12349243.html
Copyright © 2011-2022 走看看