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
    © 著作权归作者所有,转载或内容合作请联系作者
    平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务
相关推荐
lee_curry6 小时前
第四章 jvm中的垃圾回收器
java·jvm·垃圾收集器
wanhengidc6 小时前
云手机 高振畅玩不踩坑
运维·服务器·安全·web安全·智能手机
QQ1__8115175156 小时前
Spring boot名城小区物业管理系统信息管理系统源码-SpringBoot后端+Vue前端+MySQL【可直接运行】
前端·vue.js·spring boot
有谁看见我的剑了?6 小时前
linux 添加硬盘后系统识别不到硬盘处理
linux·运维·服务器
JoyCong19986 小时前
ToDesk远程屏幕墙技术白皮书:如何重塑全局运维视界
运维·电脑·远程工作
偶尔上线经常挺尸7 小时前
《100个“反常识”经验15:Nginx 502排查:从应用到内核》
运维·nginx·性能调优·反向代理·502错误·http排错
yoyo_zzm7 小时前
Laravel9.x新特性全解析
数据库·mysql·nginx
九转成圣7 小时前
Java 性能优化实战:如何将海量扁平数据高效转化为类目字典树?
java·开发语言·json
思茂信息7 小时前
CST软件如何进行参数化扫描?
运维·开发语言·javascript·windows·ecmascript·软件工程·软件需求
直奔標竿7 小时前
Java开发者AI转型第二十七课!Spring AI 个人知识库实战(六)——全栈闭环收官,解锁前端流式渲染终极技巧
java·开发语言·前端·人工智能·后端·spring