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.
或
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(浏览器/ native )等的风格而异。这个组中有一个有趣的讨论 - https://groups.google.com/forum/#!topic/reactjs/G6pljvpTGX0 .需要注意的最重要的一点是更新是分批进行的,不会同步发生。您可以通过查看关键字 batchingstrategy
的源代码来了解有关各种实现的更多信息。 .
关于javascript - React 中的事件循环是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37410283/