javascript - React 中的事件循环是什么?

标签 javascript reactjs

React 事件循环在一些关于 Virtual DOM 的文章中被提及。一些例子(粗体是我的):

Whenever you call setState on a component, React will mark it as dirty. At the end of the event loop, React looks at all the dirty components and re-renders them.

React diff’s algorithm

Most notably, changes to the virtual DOM are not guaranteed to take effect immediately. This allows React to wait until the end of its event loop before it even touches the real DOM at all.

React Demystified

但是,我找不到关于这个事件循环的任何文档。目前存在吗?它有哪些阶段?它有什么影响?

最佳答案

请注意,我不回答具体问题,因为主题是移动目标。它没有具体记录的原因是因为它的实现因 React(浏览器/ native )等的风格而异。这个组中有一个有趣的讨论 - https://groups.google.com/forum/#!topic/reactjs/G6pljvpTGX0 .需要注意的最重要的一点是更新是分批进行的,不会同步发生。您可以通过查看关键字 batchingstrategy 的源代码来了解有关各种实现的更多信息。 .

关于javascript - React 中的事件循环是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37410283/

相关文章:

python - 预检响应 FLASK CORS 中的 Access-Control-Allow-Methods 不允许方法 PUT

reactjs - 在react-native中隐藏键盘

javascript - 通过单击 react.js 传递 id

javascript - 每次 setInterval 触发时都会发生 SyntaxError

JavaScript 文件在 Laravel 中无法正确加载

javascript - 二叉树添加未定义的节点

css - React 在组件后面添加背景图片

javascript - 使用 JavaScript 向 JSON 对象添加新属性(元素)

javascript - ajax成功后window.location.href不工作

reactjs - 如何左对齐按钮中的标签