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
    © 著作权归作者所有,转载或内容合作请联系作者
    平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务
相关推荐
熊猫钓鱼>_>2 分钟前
深入理解Java堆栈:从原理到面试实战
java·开发语言·面试·职场和发展·面向对象·堆栈·oop
bloglin999992 分钟前
ubuntu系使用root用户登录显示密码错误
linux·运维·ubuntu
ccino .4 分钟前
【SSRF漏洞及自动化扫描插件】
运维·自动化
70asunflower5 分钟前
[特殊字符] Flameshot 完全指南:Ubuntu 下的终极截图工具
linux·运维·ubuntu
cici158746 分钟前
基于MATLAB的非正交多址(NOMA)系统协同中继技术提升小区边缘用户性能实现
java·服务器·matlab
不想写bug呀6 分钟前
MySQL事务介绍
数据库·mysql
千航@abc7 分钟前
Win10/Win11 DCOM服务器进程启动器 CPU 占用过高解决方法
运维·安全·病毒·window10·window11·dcom进程·系统进程资源占用高
bigdata-rookie8 分钟前
Starrocks 数据模型
java·前端·javascript
hwj运维之路15 分钟前
Docker面试题汇总系列
运维·docker·云原生·容器
蜡笔小炘16 分钟前
LVS -- 部署NAT模式集群案例
linux·运维·服务器·lvs