Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setState #101

Open
Lawguancong opened this issue Oct 12, 2021 · 0 comments
Open

setState #101

Lawguancong opened this issue Oct 12, 2021 · 0 comments

Comments

@Lawguancong
Copy link
Owner

Lawguancong commented Oct 12, 2021

流程

  • 首先,setState 会产生当前更新的优先级(老版本用 expirationTime ,新版本用 lane )。
    接下来 React 会从 fiber Root 根部 fiber 向下调和子节点,调和阶段将对比发生更新的地方,更新对比 expirationTime ,找到发生更新的组件,合并 state,然后触发 render 函数,得到新的 UI 视图层,完成 render 阶段。
    接下来到 commit 阶段,commit 阶段,替换真实 DOM ,完成此次更新流程。
    接下来会执行 setState 中 callback 函数,如上的()=>{ console.log(this.state.number) },到此为止完成了一次 setState 全过程。
    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant