Skip to content

Commit 910901e

Browse files
committed
Updated
1 parent 4b4a8e0 commit 910901e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/content/reference/react/startTransition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: startTransition
44

55
<Intro>
66

7-
`startTransition` lets you update without blocking the UI.
7+
`startTransition` lets you render a part of the UI in the background.
88

99
```js
1010
startTransition(action)
@@ -61,7 +61,7 @@ function TabContainer() {
6161

6262
* Transition updates can't be used to control text inputs.
6363

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.
6565

6666
---
6767

src/content/reference/react/useTransition.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useTransition
44

55
<Intro>
66

7-
`useTransition` is a React Hook that lets you update without blocking the UI.
7+
`useTransition` is a React Hook that lets you render a part of the UI in the background.
88

99
```js
1010
const [isPending, startTransition] = useTransition()
@@ -95,7 +95,7 @@ function SubmitButton({ submitAction }) {
9595

9696
#### Parameters {/*starttransition-parameters*/}
9797

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).
9999

100100
#### Returns {/*starttransition-returns*/}
101101

@@ -107,7 +107,7 @@ function SubmitButton({ submitAction }) {
107107

108108
* 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.
109109

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.
111111

112112
* 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)).
113113

@@ -117,7 +117,7 @@ function SubmitButton({ submitAction }) {
117117

118118
* Transition updates can't be used to control text inputs.
119119

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.
121121

122122
## Usage {/*usage*/}
123123

@@ -161,9 +161,7 @@ function CheckoutForm() {
161161
}
162162
```
163163

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.
167165

168166
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`.
169167

@@ -202,7 +200,7 @@ export default function App({}) {
202200
const [quantity, setQuantity] = useState(1);
203201
const [isPending, startTransition] = useTransition();
204202

205-
const updateQuantityAction = newQuantity => {
203+
const updateQuantityAction = async newQuantity => {
206204
// To access the pending state of a transition,
207205
// call startTransition again.
208206
startTransition(async () => {
@@ -1663,9 +1661,7 @@ startTransition(() => {
16631661
});
16641662
```
16651663
1666-
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:
16691665
16701666
```js
16711667
startTransition(() => {
@@ -1758,7 +1754,7 @@ function setState() {
17581754
}
17591755
```
17601756
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*/}
17621758
17631759
If you `await` inside `startTransition`, you might see the updates happen out of order.
17641760
@@ -1934,6 +1930,6 @@ export async function updateQuantity(newName) {
19341930
19351931
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.
19361932
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.
19381934
19391935

0 commit comments

Comments
 (0)