Skip to content

Commit d69abb8

Browse files
committed
tweaks
1 parent 6da0f3b commit d69abb8

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

src/content/reference/react/useTransition.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function TabContainer() {
5555
const [isPending, startTransition] = useTransition();
5656
const [tab, setTab] = useState('about');
5757

58-
function selectTabAction(nextTab) {
58+
function selectTab(nextTab) {
5959
startTransition(() => {
6060
setTab(nextTab);
6161
});
@@ -64,39 +64,30 @@ function TabContainer() {
6464
}
6565
```
6666

67-
The function passed to `startTransition` is called an Action. If the Action is async, React will wait for the async update to finish before transitioning the UI to the updated state:
68-
69-
```js {6}
70-
function TabButton({data, setData}) {
71-
const [isPending, startTransition] = useTransition();
72-
73-
function updateAction(data) {
74-
startTransition(async () => {
75-
const newData = await updateData(data);
76-
77-
// Note: currently, an additional startTransition
78-
// is needed after any async requests. See Caveats.
79-
startTransition(() => {
80-
setData(data);
81-
});
82-
});
83-
}
84-
// ...
85-
}
86-
```
87-
8867
<Note>
89-
#### By convention, functions inside `startTransition` are called "Actions". {/*by-convention-functions-that-call-transitions-are-called-actions*/}
68+
#### Functions called in `startTransition` are called "Actions". {/*functions-called-in-starttransition-are-called-actions*/}
9069

91-
The function passed to `startTransition` is called an "Action". By convention, any callback called inside `startTransition` (such as a callback prop) include the "Action" suffix.
70+
The function passed to `startTransition` is called an "Action". By convention, any callback called inside `startTransition` (such as a callback prop) are named `action` or include the "Action" suffix:
9271

93-
Transitions can include multiple Actions, such as an Action to update a local component, and another Action to navigate to the next route. Transitions support:
72+
```js {1,9}
73+
function SubmitButton({ submitAction }) {
74+
const [isPending, startTranstion] = useTranstion();
9475

95-
- **Pending states**: Actions provide a pending state that starts at the beginning of the Transition and automatically resets when the final state update is committed.
96-
- **Optimistic updates**: Actions support the new [`useOptimistic`](#new-hook-optimistic-updates) hook so you can show users instant feedback while the Action is in progress.
97-
- **Error handling**: Actions provide error handling so you can display Error Boundaries when an Action fails, and revert optimistic updates to their original value automatically.
98-
- **Forms**: `<form>` elements now support passing functions to the `action` and `formAction` props. Passing functions to the `action` props use Actions by default and reset the form automatically after submission.
76+
return (
77+
<button
78+
disabled={isPending}
79+
onClick={() => {
80+
startTransition(() => {
81+
submitAction();
82+
});
83+
}}
84+
>
85+
Submit
86+
</button>
87+
);
88+
}
9989

90+
```
10091

10192
</Note>
10293

0 commit comments

Comments
 (0)