渲染
一句话解释
渲染是 处理的 组件 evaluating 它的 Props and 状态到 produce JSX (虚拟 DOM) 那个描述 UI.
用大白话说
In React, "渲染" has two meanings: (1) the component function executing and returning JSX, and (2) React updating the real DOM to match that JSX.
When state or props change, React calls the component function again — this is a render. The function returns new JSX (a new virtual DOM tree). React compares this to the previous tree (reconciliation) and updates the real DOM with the minimal changes.
A render does not always mean the DOM changes — if the JSX is identical, React skips the DOM update. Also, a parent rendering causes all children to render by default (unless memoized). Rendering is cheap; DOM mutations are expensive. React's optimization is to minimize DOM mutations.
示例
function Clock({ time }) {
// This function "renders" — it runs and returns JSX
return <h1>It is {time}</h1>;
}
// When `time` changes, React calls Clock() again (re-render),
// diffs the new JSX, and updates only the changed text.每个时间 时间 更改, React re-渲染 Clock 组件通过 calling 函数再次, 然后更新 DOM.
相关术语
相关资源
相关课程
- 组件
理解如何组件渲染.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。