Deep Dive React 4 How does React State actually work

In other word, how does React handle updates?

How React communicates with the renderer

复制代码
setState(...args) {
  this.updater.enqueueSetState(this, ...args);
}

The Update

  • When we call setState, React adds the passed data to a queue
  • The updates are later handled one by one, but the changes are applied at the same time at the end (flushed to the DOM at once)

Lifecycle & 2 phases


Screen Shot 2022-08-18 at 9.12.01 PM.png

复制代码
static getDerivedStateFromProps(props, state) {
  console.log('this is the only static lifecycle methods, cannot access this, window');
  return state;
}

Update Steps

happend in 2 phases

  1. setState is called
  2. data is added to a queue
  3. React starts handling the update
  4. new state is calculated + getDerivedStateFromProps is called
  5. shouldComponentUpdate is called with final (derived) state
  6. render is called

  1. DOM changes are made
  2. componentDidUpdate is called
    © 著作权归作者所有,转载或内容合作请联系作者
    平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务
相关推荐
盼哥PyAI实验室5 小时前
MySQL 数据库基础:字段判空、逻辑查找、排序、限制、模糊搜索与聚合函数全解析
数据库·mysql·oracle
后端小张6 小时前
【JAVA进阶】Spring Boot 核心知识点之自动配置:原理与实战
java·开发语言·spring boot·后端·spring·spring cloud·自动配置
v***91308 小时前
【MySQL】JDBC的连接
数据库·mysql
v***446711 小时前
【MySQL — 数据库基础】深入理解数据库服务与数据库关系、MySQL连接创建、客户端工具及架构解析
数据库·mysql·架构
ascarl201011 小时前
记录一下es节点掉线后修复好了的情况
运维·jenkins
3***C74411 小时前
Spring Boot 整合 log4j2 日志配置教程
spring boot·单元测试·log4j
tg-zm88999611 小时前
2025返利商城源码/挂机自动收益可二开多语言/自定义返利比例/三级分销理财商城
java·mysql·php·laravel·1024程序员节
X***C86211 小时前
SpringBoot:几种常用的接口日期格式化方法
java·spring boot·后端
i***t91911 小时前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
i***486111 小时前
MySQL中的GROUP_CONCAT()函数详解与实战应用
数据库·mysql