React 中的事件循环是什么?
What is an event loop in React?
一些关于虚拟 DOM 的文章中提到了 React 事件循环。一些例子(粗体是我的):
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 (browser/native) 等的风格而异。这个组中有一个有趣的讨论 - https://groups.google.com/forum/#!topic/reactjs/G6pljvpTGX0. The most important thing to note about it is that the updates are batched and don't happen synchronously. You can read more about the various implementations by looking at the source code for the keyword batchingstrategy
.
一些关于虚拟 DOM 的文章中提到了 React 事件循环。一些例子(粗体是我的):
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 (browser/native) 等的风格而异。这个组中有一个有趣的讨论 - https://groups.google.com/forum/#!topic/reactjs/G6pljvpTGX0. The most important thing to note about it is that the updates are batched and don't happen synchronously. You can read more about the various implementations by looking at the source code for the keyword batchingstrategy
.