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/startTransition.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: startTransition
4
4
5
5
<Intro>
6
6
7
-
`startTransition` lets you update without blocking the UI.
7
+
`startTransition` lets you render a part of the UI in the background.
8
8
9
9
```js
10
10
startTransition(action)
@@ -61,7 +61,7 @@ function TabContainer() {
61
61
62
62
* Transition updates can't be used to control text inputs.
63
63
64
-
* If there are multiple ongoing Transitions, React currently batches them together. This is a limitation that will likely be removed in a future release.
64
+
* If there are multiple ongoing Transitions, React currently batches them together. This is a limitation that may be removed in a future release.
@@ -95,7 +95,7 @@ function SubmitButton({ submitAction }) {
95
95
96
96
#### Parameters {/*starttransition-parameters*/}
97
97
98
-
*`action`: A function that updates some state by calling one or more [`set` functions](/reference/react/useState#setstate). React immediately calls `action` with no parameters and marks all state updates scheduled synchronously during the `action` function call as Transitions. Any async calls awaited in the `action` will be included in the transition, but currently require wrapping any `set` functions after the `await` in an additional `startTransition` (see [Troubleshooting](#react-doesnt-treat-my-state-update-after-await-as-a-transition)). State updates marked as Transitions will be [non-blocking](#marking-a-state-update-as-a-non-blocking-transition) and [will not display unwanted loading indicators.](#preventing-unwanted-loading-indicators).
98
+
*`action`: A function that updates some state by calling one or more [`set` functions](/reference/react/useState#setstate). React immediately calls `action` with no parameters and marks all state updates scheduled synchronously during the `action` function call as Transitions. Any async calls awaited in the `action` will be included in the transition, but currently require wrapping any `set` functions after the `await` in an additional `startTransition` (see [Troubleshooting](#react-doesnt-treat-my-state-update-after-await-as-a-transition)). State updates marked as Transitions will be [non-blocking](#marking-a-state-update-as-a-non-blocking-transition) and [will not display unwanted loading indicators](#preventing-unwanted-loading-indicators).
99
99
100
100
#### Returns {/*starttransition-returns*/}
101
101
@@ -107,7 +107,7 @@ function SubmitButton({ submitAction }) {
107
107
108
108
* 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 value, try [`useDeferredValue`](/reference/react/useDeferredValue) instead.
109
109
110
-
* The function you pass to the of `startTransition` is called immediately, marking all state updates that happen while it executes as Transitions. If you try to perform state updates in a `setTimeout`, for example, they won't be marked as Transitions.
110
+
* The function you pass to `startTransition` is called immediately, marking all state updates that happen while it executes as Transitions. If you try to perform state updates in a `setTimeout`, for example, they won't be marked as Transitions.
111
111
112
112
* You must wrap any state updates after any async requests in another `startTransition` to mark them as Transitions. This is a known limitation that we will fix in the future (see [Troubleshooting](#react-doesnt-treat-my-state-update-after-await-as-a-transition)).
113
113
@@ -117,7 +117,7 @@ function SubmitButton({ submitAction }) {
117
117
118
118
* Transition updates can't be used to control text inputs.
119
119
120
-
* If there are multiple ongoing Transitions, React currently batches them together. This is a limitation that will likely be removed in a future release.
120
+
* If there are multiple ongoing Transitions, React currently batches them together. This is a limitation that may be removed in a future release.
121
121
122
122
## Usage {/*usage*/}
123
123
@@ -161,9 +161,7 @@ function CheckoutForm() {
161
161
}
162
162
```
163
163
164
-
The function passed to `startTransition` is called the "Action". In Actions, you can perform side effects and update state within a Transition, without blocking the UI. A Transition can include multiple Actions, and while the Transition is in progress, your UI stays responsive in the middle of a re-render.
165
-
166
-
For example, if the user clicks a tab but then changes their mind and clicks another tab, they can do that without waiting for the first re-render to finish. But if the Action is performing a side effect, such as submitting a form, React will wait for the side effect to finish before changing the tab.
164
+
The function passed to `startTransition` is called the "Action". You can update state and (optionally) perform side effects within an Action, and the work will be done in the background without blocking user interactions on the page. A Transition can include multiple Actions, and while a Transition is in progress, your UI stays responsive in the middle of the Actions. For example, if the user clicks a tab but then changes their mind and clicks another tab, the second click will be immediately handled waiting for the first update to finish.
167
165
168
166
To give the user feedback about in-progress Transitions, to `isPending` state switches to `true` at the first call to `startTransition`, and stays `true` until all Actions complete and the final state is shown to the user. Transitions wait for side effects in Actions to complete in order to [prevent unwanted loading indicators](#preventing-unwanted-loading-indicators), and you can provide immediate feedback while the Transition is in progress with `useOptimistic`.
169
167
@@ -202,7 +200,7 @@ export default function App({}) {
The function you pass to `startTransition` must be synchronous, or await an async function.
1667
-
1668
-
You can't mark an update as a Transition like this:
1664
+
The function you pass to `startTransition` must be synchronous. You can't mark an update as a Transition like this:
1669
1665
1670
1666
```js
1671
1667
startTransition(() => {
@@ -1758,7 +1754,7 @@ function setState() {
1758
1754
}
1759
1755
```
1760
1756
1761
-
### My state updates in async Transitions are out of order {/*my-state-updates-in-async-transitions-are-out-of-order*/}
1757
+
### My state updates in Transitions are out of order {/*my-state-updates-in-transitions-are-out-of-order*/}
1762
1758
1763
1759
If you `await` inside `startTransition`, you might see the updates happen out of order.
1764
1760
@@ -1934,6 +1930,6 @@ export async function updateQuantity(newName) {
1934
1930
1935
1931
When clicking multiple times, it's possible for previous requests to finish after later requests. When this happens, React currently has no way to know the intended order. This is because the updates are scheduled asynchronously, and React loses context of the order across the async boundary.
1936
1932
1937
-
This is expected. In the future, React can use [AsyncContext](https://github.com/tc39/proposal-async-context) to track the order of async updates. For common use cases, React provides higher-level abstractions like [`useActionState`](/reference/react/useActionState) and [`<form>` actions](/reference/react-dom/components/form) that handle this automatically. For advanced use cases that use async transitions directly, you'll need to implement your own queuing and abort logic to handle this.
1933
+
This is expected, because Actions within a Transition are not ordered. For common use cases, React provides higher-level abstractions like [`useActionState`](/reference/react/useActionState) and [`<form>` actions](/reference/react-dom/components/form) that handle ordering for you. For advanced use cases, you'll need to implement your own queuing and abort logic to handle this.
0 commit comments