Skip to content

Commit c70132f

Browse files
committed
docs: wrap state updates after await in startTransition
1 parent 47e64bf commit c70132f

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/content/reference/rsc/server-functions.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ function UpdateName() {
126126
const submitAction = async () => {
127127
startTransition(async () => {
128128
const {error} = await updateName(name);
129-
if (error) {
130-
setError(error);
131-
} else {
132-
setName('');
133-
}
129+
startTransition(() => {
130+
if (error) {
131+
setError(error);
132+
} else {
133+
setName('');
134+
}
135+
});
134136
})
135137
}
136138

src/content/reference/rsc/use-server.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Server Functions are exposed server endpoints and can be called anywhere in clie
179179

180180
When using a Server Function outside a [form](/reference/react-dom/components/form), call the Server Function in a [Transition](/reference/react/useTransition), which allows you to display a loading indicator, show [optimistic state updates](/reference/react/useOptimistic), and handle unexpected errors. Forms will automatically wrap Server Functions in transitions.
181181

182-
```js {9-12}
182+
```js {9-14}
183183
import incrementLike from './actions';
184184
import { useState, useTransition } from 'react';
185185

@@ -190,7 +190,9 @@ function LikeButton() {
190190
const onClick = () => {
191191
startTransition(async () => {
192192
const currentCount = await incrementLike();
193-
setLikeCount(currentCount);
193+
startTransition(() => {
194+
setLikeCount(currentCount);
195+
});
194196
});
195197
};
196198

0 commit comments

Comments
 (0)