Skip to content

Commit c6467f4

Browse files
baijinpingawxiaoxian2020daochouwangu
authored
docs(cn): translate content/docs/hooks-reference.md into Chinese (reactjs#1018)
* Update hooks-reference.md translate #batching-of-state-updates * Apply suggestions from code review Co-authored-by: TimLi <[email protected]> * Update content/docs/hooks-reference.md * Update content/docs/hooks-reference.md --------- Co-authored-by: Xavi Lee <[email protected]> Co-authored-by: TimLi <[email protected]>
1 parent ef15341 commit c6467f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

content/docs/hooks-reference.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ const [state, setState] = useState(() => {
112112

113113
需要注意的是,React 可能仍需要在跳过渲染前渲染该组件。不过由于 React 不会对组件树的“深层”节点进行不必要的渲染,所以大可不必担心。如果你在渲染期间执行了高开销的计算,则可以使用 `useMemo` 来进行优化。
114114

115-
#### Batching of state updates {#batching-of-state-updates}
115+
#### state 合并更新 {#batching-of-state-updates}
116116

117-
React may group several state updates into a single re-render to improve performance. Normally, this improves performance and shouldn't affect your application's behavior.
117+
React 可能会将多次 state 更新合并到一次的重渲染中以改善性能。通常情况下,这能够提升性能并且不影响你的应用行为。
118118

119-
Before React 18, only updates inside React event handlers were batched. Starting with React 18, [batching is enabled for all updates by default](/blog/2022/03/08/react-18-upgrade-guide.html#automatic-batching). Note that React makes sure that updates from several *different* user-initiated events -- for example, clicking a button twice -- are always processed separately and do not get batched. This prevents logical mistakes.
119+
React v18 之前,只有在 React 事件处理函数中的更新会被合并提交。从 React v18 开始, [合并更新默认在所有更新操作中启用](/blog/2022/03/08/react-18-upgrade-guide.html#automatic-batching) 。注意,React 确保*不同*的“用户发起事件”(例如连续点击按钮)的更新始终各自独立处理,不会被批量处理。这可以避免逻辑上的错误。
120120

121-
In the rare case that you need to force the DOM update to be applied synchronously, you may wrap it in [`flushSync`](/docs/react-dom.html#flushsync). However, this can hurt performance so do this only where needed.
121+
在极少数情况下,你需要强制以同步方式更新 DOM,此时可以用 [`flushSync`](/docs/react-dom.html#flushsync) 将其包裹。不过这可能会影响性能,所以只在必要时使用这种方式。
122122

123123
### `useEffect` {#useeffect}
124124

0 commit comments

Comments
 (0)