Skip to content

Commit e51fc36

Browse files
authored
docs: wrap state updates after await in startTransition (#8443)
1 parent ac61e37 commit e51fc36

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

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)