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
The `startTransition`function lets you mark a state update as a transition.
25
+
`startTransition`函数可以将 state 更新标记为 transition。
24
26
25
27
```js {7,9}
26
28
import { startTransition } from'react';
@@ -37,37 +39,37 @@ function TabContainer() {
37
39
}
38
40
```
39
41
40
-
[See more examples below.](#usage)
42
+
[请看下面的更多例子](#usage)。
41
43
42
-
#### Parameters {/*parameters*/}
44
+
#### 参数 {/*parameters*/}
43
45
44
-
*`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)
*`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.
*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.
*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.
58
+
*你传递给 `startTransition`的函数必须是同步的。React 会立即执行此函数,将其执行期间发生的所有 state 更新标记为 transition。如果你想试着稍后执行更多的 state 更新(例如,在 timeout 中),它们不会被标记为转换。
57
59
58
-
*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.
60
+
*一个被标记为 transition 的 state 更新时将会被其他 state 更新打断。例如,如果你在 transition 内部更新图表组件,但在图表重新渲染时在输入框中打字,则 React 将先处理输入 state 更新,之后才会重新启动对图表组件的渲染工作。
59
61
60
-
*Transition updates can't be used to control text inputs.
62
+
*transition 更新不能用于控制文本输入。
61
63
62
-
*If there are multiple ongoing transitions, React currently batches them together. This is a limitation that will likely be removed in a future release.
### Marking a state update as a non-blocking transition {/*marking-a-state-update-as-a-non-blocking-transition*/}
70
+
### 将 state 更新标记为非阻塞 transition {/*marking-a-state-update-as-a-non-blocking-transition*/}
69
71
70
-
You can mark a state update as a *transition* by wrapping it in a `startTransition` call:
72
+
你可以通过将一个 state 包裹在 `startTransition` 回调中,将其更新标记为一个 **transition**:
71
73
72
74
```js {7,9}
73
75
import { startTransition } from'react';
@@ -84,14 +86,14 @@ function TabContainer() {
84
86
}
85
87
```
86
88
87
-
Transitions let you keep the user interface updates responsive even on slow devices.
89
+
transition 可以让用户界面在慢速设备上保持更新响应。
88
90
89
-
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.
`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.
0 commit comments