You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react/Profiler.md
+28-28
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: <Profiler>
4
4
5
5
<Intro>
6
6
7
-
`<Profiler>`lets you measure rendering performance of a React tree programmatically.
7
+
`<Profiler>`允许你编程式测量 React 树的渲染性能。
8
8
9
9
```js
10
10
<Profiler id="App" onRender={onRender}>
@@ -18,55 +18,55 @@ title: <Profiler>
18
18
19
19
---
20
20
21
-
## Reference {/*reference*/}
21
+
## 参考 {/*reference*/}
22
22
23
23
### `<Profiler>` {/*profiler*/}
24
24
25
-
Wrap a component tree in a `<Profiler>`to measure its rendering performance.
25
+
使用 `<Profiler>`包裹组件树,以测量其渲染性能。
26
26
27
27
```js
28
28
<Profiler id="App" onRender={onRender}>
29
29
<App />
30
30
</Profiler>
31
31
```
32
32
33
-
#### Props {/*props*/}
33
+
#### 参数 {/*props*/}
34
34
35
-
*`id`: A string identifying the part of the UI you are measuring.
36
-
*`onRender`: An [`onRender`callback](#onrender-callback) that React calls every time components within the profiled tree update. It receives information about what was rendered and how much time it took.
*Profiling adds some additional overhead, so **it is disabled in the production build by default.** To opt into production profiling, you need to enable a [special production build with profiling enabled.](https://fb.me/react-profiling)
*`id`: The string `id` prop of the `<Profiler>`tree that has just committed. This lets you identify which part of the tree was committed if you are using multiple profilers.
57
-
*`phase`: `"mount"`, `"update"`or`"nested-update"`. This lets you know whether the tree has just been mounted for the first time or re-rendered due to a change in props, state, or hooks.
58
-
*`actualDuration`: The number of milliseconds spent rendering the `<Profiler>`and its descendants for the current update. This indicates how well the subtree makes use of memoization (e.g. [`memo`](/reference/react/memo)and[`useMemo`](/reference/react/useMemo)). Ideally this value should decrease significantly after the initial mount as many of the descendants will only need to re-render if their specific props change.
59
-
*`baseDuration`: The number of milliseconds estimating how much time it would take to re-render the entire `<Profiler>`subtree without any optimizations. It is calculated by summing up the most recent render durations of each component in the tree. This value estimates a worst-case cost of rendering (e.g. the initial mount or a tree with no memoization). Compare `actualDuration`against it to see if memoization is working.
60
-
*`startTime`: A numeric timestamp for when React began rendering the current update.
61
-
*`endTime`: A numeric timestamp for when React committed the current update. This value is shared between all profilers in a commit, enabling them to be grouped if desirable.
Wrap the `<Profiler>`component around a React tree to measure its rendering performance.
69
+
使用 `<Profiler>`组件包裹 React 树以测量其渲染性能。
70
70
71
71
```js {2,4}
72
72
<App>
@@ -77,25 +77,25 @@ Wrap the `<Profiler>` component around a React tree to measure its rendering per
77
77
</App>
78
78
```
79
79
80
-
It requires two props: an `id` (string) and an `onRender`callback (function) which React calls any time a component within the tree "commits" an update.
Profiling adds some additional overhead, so **it is disabled in the production build by default.** To opt into production profiling, you need to enable a [special production build with profiling enabled.](https://fb.me/react-profiling)
`<Profiler>`lets you gather measurements programmatically. If you're looking for an interactive profiler, try the Profiler tab in [React Developer Tools](/learn/react-developer-tools). It exposes similar functionality as a browser extension.
0 commit comments