Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(cn): update useDeferredValue translation #1626

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/content/reference/react/useDeferredValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ function SearchPage() {
#### 参数 {/*parameters*/}

* `value`: 你想延迟的值,可以是任何类型。
* <CanaryBadge title="This feature is only available in the Canary channel" /> **optional** `initialValue`: A value to use during the initial render of a component. If this option is omitted, `useDeferredValue` will not defer during the initial render, because there's no previous version of `value` that it can render instead.
* <CanaryBadge title="这个功能只在 Canary 渠道中可用" /> **可选的** `initialValue`: 组件初始渲染时使用的值。如果省略此选项,`useDeferredValue` 在初始渲染期间不会延迟,因为没有以前的版本可以渲染。

#### 返回值 {/*returns*/}

- `currentValue`: During the initial render, the returned deferred value will be the same as the value you provided. During updates, React will first attempt a re-render with the old value (so it will return the old value), and then try another re-render in the background with the new value (so it will return the updated value).
- `currentValue`: 在初始渲染期间,返回的延迟值将与你提供的值相同。在更新期间,React 首先尝试使用旧值重新渲染(因此返回旧值),然后在后台尝试使用新值重新渲染(因此返回更新后的值)。

<Canary>

In the latest React Canary versions, `useDeferredValue` returns the `initialValue` on initial render, and schedules a re-render in the background with the `value` returned.
在最新的 React Canary 版本中,`useDeferredValue` 在初始渲染期间返回 `initialValue`,并在后台使用返回的 `value` 重新调度渲染。

</Canary>

#### 注意事项 {/*caveats*/}

- When an update is inside a Transition, `useDeferredValue` always returns the new `value` and does not spawn a deferred render, since the update is already deferred.
- 当更新发生在 Transition 内部时,`useDeferredValue` 总是返回新的 `value` 并且不会产生延迟渲染,因为该更新已经被延迟了。

- The values you pass to `useDeferredValue` should either be primitive values (like strings and numbers) or objects created outside of rendering. If you create a new object during rendering and immediately pass it to `useDeferredValue`, it will be different on every render, causing unnecessary background re-renders.
- 传递给 `useDeferredValue` 的值应该是原始值(如字符串和数字)或是在渲染之外创建的对象。如果你在渲染期间创建一个新对象并立即将其传递给 `useDeferredValue`,它在每次渲染时都会不同,从而导致不必要的后台重新渲染。

- 当 `useDeferredValue` 接收到与之前不同的值(使用 [`Object.is`](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/is) 进行比较)时,除了当前渲染(此时它仍然使用旧值),它还会安排一个后台重新渲染。这个后台重新渲染是可以被中断的,如果 `value` 有新的更新,React 会从头开始重新启动后台渲染。举个例子,如果用户在输入框中的输入速度比接收延迟值的图表重新渲染的速度快,那么图表只会在用户停止输入后重新渲染。

Expand Down