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): translate reference/react/startTransition into Chinese #1104

Merged
merged 37 commits into from
May 18, 2023
Merged
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8e99c7d
docs(cn): translate the reference/react/startTransition page
Davont Mar 27, 2023
449328f
docs(cn): translate the reference/react/startTransition page
Davont Mar 28, 2023
a3697e1
docs(cn): translate the reference/react/startTransition page
Davont Mar 28, 2023
51e15e3
Merge branch 'main' into react-startTransition
awxiaoxian2020 Mar 28, 2023
e7d7944
Merge branch 'main' into react-startTransition
Davont Mar 28, 2023
2991975
Merge branch 'main' into react-startTransition
Davont Mar 28, 2023
5fc7961
Merge branch 'main' into react-startTransition
awxiaoxian2020 Mar 28, 2023
133912d
Merge branch 'main' into react-startTransition
Davont Mar 29, 2023
1b79564
Merge branch 'main' into react-startTransition
Davont Mar 30, 2023
7f35854
Merge branch 'main' into react-startTransition
Davont Mar 30, 2023
ab29c06
Merge branch 'main' into react-startTransition
awxiaoxian2020 Mar 30, 2023
2513d94
Merge branch 'main' into react-startTransition
Davont Apr 3, 2023
dc45956
Merge branch 'main' into react-startTransition
Davont Apr 4, 2023
a3f2d47
Merge branch 'main' into react-startTransition
awxiaoxian2020 Apr 5, 2023
2e0cb6c
Merge branch 'main' into react-startTransition
Davont Apr 6, 2023
2fbbf47
Merge branch 'main' into react-startTransition
Davont Apr 7, 2023
99c8a0e
Merge branch 'main' into react-startTransition
Davont Apr 10, 2023
15e88ac
Merge branch 'main' into react-startTransition
Davont Apr 10, 2023
ea189cc
Apply suggestions from code review [skip ci]
awxiaoxian2020 Apr 11, 2023
edc412c
Merge branch 'main' into react-startTransition
Davont Apr 13, 2023
14e77f0
Merge branch 'main' into react-startTransition
Davont Apr 17, 2023
5054651
docs(cn): translate the choosing-the-state-structure page
Davont Apr 18, 2023
36b3aab
docs(cn): translate the choosing-the-state-structure page
Davont Apr 18, 2023
15acf5b
Merge branch 'main' into react-startTransition
Davont Apr 20, 2023
86b1c45
Merge branch 'main' into react-startTransition
Davont Apr 21, 2023
3471523
Merge branch 'main' into react-startTransition
Davont Apr 22, 2023
8de3233
Merge branch 'main' into react-startTransition
Davont Apr 24, 2023
3023339
Update src/content/reference/react/startTransition.md
Davont Apr 24, 2023
95a10a1
Update src/content/reference/react/startTransition.md
Davont Apr 24, 2023
895c4a9
Update src/content/reference/react/startTransition.md
Davont Apr 24, 2023
36d61fc
Update src/content/reference/react/startTransition.md
Davont Apr 24, 2023
61ef7d8
Update src/content/reference/react/startTransition.md
Davont Apr 24, 2023
4dd59a0
Update src/content/reference/react/startTransition.md
Davont Apr 24, 2023
cd7f76d
Merge branch 'reactjs:main' into react-startTransition
Davont Apr 24, 2023
74d7c0c
Merge branch 'main' into react-startTransition
Davont Apr 27, 2023
77cee6c
Update src/content/reference/react/startTransition.md
Yucohny May 18, 2023
49d552d
Update src/content/reference/react/startTransition.md
Yucohny May 18, 2023
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
46 changes: 24 additions & 22 deletions src/content/reference/react/startTransition.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
title: startTransition
translators:
- Davont
---

<Intro>

`startTransition` lets you update the state without blocking the UI.
`startTransition` 可以让你在不阻塞 UI 的情况下更新 state

```js
startTransition(scope)
Expand All @@ -16,11 +18,11 @@ startTransition(scope)

---

## Reference {/*reference*/}
## 参考 {/*reference*/}

### `startTransition(scope)` {/*starttransitionscope*/}

The `startTransition` function lets you mark a state update as a transition.
`startTransition` 函数可以将 state 更新标记为 transition

```js {7,9}
import { startTransition } from 'react';
Expand All @@ -37,37 +39,37 @@ function TabContainer() {
}
```

[See more examples below.](#usage)
[请看下面的更多例子](#usage)

#### Parameters {/*parameters*/}
#### 参数 {/*parameters*/}

* `scope`: A function that updates some state by calling one or more [`set` functions.](/reference/react/useState#setstate) React immediately calls `scope` with no parameters and marks all state updates scheduled synchronously during the `scope` function call as transitions. They will be [non-blocking](/reference/react/useTransition#marking-a-state-update-as-a-non-blocking-transition) and [will not display unwanted loading indicators.](/reference/react/useTransition#preventing-unwanted-loading-indicators)
* `scope`: 一个调用一个或多个 [`set` 函数](/reference/react/useState#setstate) 来更新 state 的函数。React 会立即调用没有参数的 `scope`,并将在 `scope` 函数调用期间,调度所有的 state,同步更新标记为 transition。它们将是 [非阻塞的](/reference/react/useTransition#marking-a-state-update-as-a-non-blocking-transition),并且 [不会显示不想要的加载提示](/reference/react/useTransition#preventing-unwanted-loading-indicators)
Yucohny marked this conversation as resolved.
Show resolved Hide resolved

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

`startTransition` does not return anything.
`startTransition` 不返回任何内容。

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

* `startTransition` does not provide a way to track whether a transition is pending. To show a pending indicator while the transition is ongoing, you need [`useTransition`](/reference/react/useTransition) instead.
* `startTransition` 没有提供一种跟踪 transition 是否处于待定状态的方法。为了在 transition 进行时显示一个待定状态的指示器,你需要使用 [`useTransition`](/reference/react/useTransition)

* You can wrap an update into a transition only if you have access to the `set` function of that state. If you want to start a transition in response to some prop or a custom Hook return value, try [`useDeferredValue`](/reference/react/useDeferredValue) instead.
* 只有当你能访问某个 state 的 `set` 函数时,你才能将它的更新包裹到 transition 中。如果你想根据一些 prop 或自定义 Hook 的返回值来启动一个 transition,请尝试使用 [`useDeferredValue`](/reference/react/useDeferredValue)
Yucohny marked this conversation as resolved.
Show resolved Hide resolved

* The function you pass to `startTransition` must be synchronous. React immediately executes this function, marking all state updates that happen while it executes as transitions. If you try to perform more state updates later (for example, in a timeout), they won't be marked as transitions.
* 你传递给 `startTransition` 的函数必须是同步的。React 会立即执行此函数,将其执行期间发生的所有 state 更新标记为 transition。如果你想试着稍后执行更多的 state 更新(例如,在 timeout 中),它们不会被标记为转换。

* A state update marked as a transition will be interrupted by other state updates. For example, if you update a chart component inside a transition, but then start typing into an input while the chart is in the middle of a re-render, React will restart the rendering work on the chart component after handling the input state update.
* 一个被标记为 transition 的 state 更新时将会被其他 state 更新打断。例如,如果你在 transition 内部更新图表组件,但在图表重新渲染时在输入框中打字,则 React 将先处理输入 state 更新,之后才会重新启动对图表组件的渲染工作。

* Transition updates can't be used to control text inputs.
* transition 更新不能用于控制文本输入。

* If there are multiple ongoing transitions, React currently batches them together. This is a limitation that will likely be removed in a future release.
* 如果有多个正在进行的 transition,当前 React 会将它们集中在一起处理。这是一个限制,在未来的版本中可能会被移除。

---

## Usage {/*usage*/}
## 使用方法 {/*usage*/}

### Marking a state update as a non-blocking transition {/*marking-a-state-update-as-a-non-blocking-transition*/}
### state 更新标记为非阻塞 transition {/*marking-a-state-update-as-a-non-blocking-transition*/}

You can mark a state update as a *transition* by wrapping it in a `startTransition` call:
你可以通过将一个 state 包裹在 `startTransition` 回调中,将其更新标记为一个 **transition**:

```js {7,9}
import { startTransition } from 'react';
Expand All @@ -84,14 +86,14 @@ function TabContainer() {
}
```

Transitions let you keep the user interface updates responsive even on slow devices.
transition 可以让用户界面在慢速设备上保持更新响应。

With a transition, your UI stays responsive in the middle of a re-render. For example, if the user clicks a tab but then change their mind and click another tab, they can do that without waiting for the first re-render to finish.
通过 transition,你的 UI 在重新渲染过程中保持响应。例如,如果用户单击一个选项卡后又改变主意并单击另一个选项卡,则可以在第一次重新渲染完成之前执行此操作而无需等待。

<Note>

`startTransition` is very similar to [`useTransition`](/reference/react/useTransition), except that it does not provide the `isPending` flag to track whether a transition is ongoing. You can call `startTransition` when `useTransition` is not available. For example, `startTransition` works outside components, such as from a data library.
`startTransition` [`useTransition`](/reference/react/useTransition) 非常相似,但它不提供 `isPending` 标志来跟踪一个 transition 是否正在进行。你可以在 `useTransition` 不可用时调用 `startTransition`。例如,在组件外部(如从数据库中)使用 `startTransition`

[Learn about transitions and see examples on the `useTransition` page.](/reference/react/useTransition)
[`useTransition` 页面上了解 transition 并查看示例](/reference/react/useTransition)

</Note>