元素是构成 React 应用的最小砖块。
元素不同于DOM元素,也不同于组件。
1⃣️ 创建:想要将一个 React 元素渲染到根 DOM 节点中,只需把它们一起传入 ReactDOM.render()
2⃣️ 更新:React 元素是不可变对象。一旦被创建,你就无法更改它的子元素或者属性。一个元素就像电影的单帧:它代表了某个特定时刻的 UI。
根据我们已有的知识,更新 UI 唯一的方式是创建一个全新的元素,并将其传入 ReactDOM.render()
。
⚠️ 大多数 React 应用只会调用一次 ReactDOM.render()