前端框架React

来源:互联网 发布:51单片机怎么烧程序 编辑:程序博客网 时间:2024/06/05 05:19

1.把元素渲染进DOM

To render a React element into a root DOM node, pass both to ReactDOM.render()
为了把一个react元素渲染进DOM,把他们两个都传进ReactDOM.render()方法。

const element = <h1>Hello, world</h1>;ReactDOM.render(  element,  document.getElementById('root'));



2.更新渲染的元素


React elements are immutable. Once you create an element, you can't change its children or attributes. An element is like a single frame in a movie: it represents the UI at a certain point in time.

React元素是不可变的。一旦你创建一个元素,你不能改变他的Children或者属性。

With our knowledge so far, the only way to update the UI is to create a new element, and pass it to ReactDOM.render().

到目前我们所学到的唯一的方法去更新UI就是去创建一个新的元素,然后传进render()方法。



3.React只会更新需要更新的部分

纵然上面每次我们都要创建新的元素,但是react DOM 会用现在的元素(包括元素的Children)和之前的元素进行比较,并且只会让DOM更新需要更新的部分。


即使我们创建了一个完整的元素,但是只有text node被React DOM更新了,因为只有text node的内容改变了。


0 0
原创粉丝点击