简体   繁体   English

“React动态更新DOM”究竟意味着什么?

[英]What does it mean exactly that “React updates DOM dynamically”?

The ReactJS website states that, ReactJS网站声明,

When the data changes, React conceptually hits the "refresh" button, and knows to only update the changed parts . 当数据发生变化时,React在概念上会点击“刷新”按钮,并且知道只更新已更改的部分

What does this mean exactly? 这究竟是什么意思?

How is this achieved? 这是如何实现的?

How is this different from what AngularJS does? 这与AngularJS的不同之处有何不同?

Reactjs create a virtual DOM and does not touch to the real DOM. Reactjs创建一个虚拟DOM,而不是触及真正的DOM。 Then when some of DOM changed, it will use diff algorithm to find out what is different from previous state of DOM elements, finally just replace that changes. 然后当一些DOM改变时,它将使用diff算法找出与先前DOM元素状态不同的东西,最后只需替换那些改变。 You can see this link for that algorithm to have more understanding. 您可以看到算法的此链接有更多的了解。 And you have to know what is shadow DOM as well. 你必须知道什么是影子DOM。

Here's a great resource explaining why ReactJS was developed and how it differs from other frameworks like AngularJS: 这里有一个很好的资源解释了ReactJS的开发原因以及它与AngularJS等其他框架的区别:

http://www.quora.com/Pete-Hunt/Posts/Facebooks-React-vs-AngularJS-A-Closer-Look http://www.quora.com/Pete-Hunt/Posts/Facebooks-React-vs-AngularJS-A-Closer-Look

"A lot of the heavyweight contenders for MVVM frameworks have a hard time rendering large amounts of data, like in lists and such. React doesn't have that problem, as it renders only what's changed. “许多MVVM框架的重量级竞争者很难渲染大量数据,比如列表等.React没有那个问题,因为它只渲染了改变的内容。

For example, if a user is viewing a list of 100 items rendered with React, and he or she changes the third one down somehow, only that item gets rerendered, leaving the other 99 items unchanged." 例如,如果用户正在查看使用React呈现的100个项目的列表,并且他或她以某种方式更改了第三个项目,则只有该项目被重新呈现,而其他99个项目保持不变。“

( https://www.codementor.io/reactjs/tutorial/react-vs-angularjs ) https://www.codementor.io/reactjs/tutorial/react-vs-angularjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM