Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/content/reference/rsc/server-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ function UpdateName() {
const submitAction = async () => {
startTransition(async () => {
const {error} = await updateName(name);
if (error) {
setError(error);
} else {
setName('');
}
startTransition(() => {
if (error) {
setError(error);
} else {
setName('');
}
});
})
}

Expand Down
6 changes: 4 additions & 2 deletions src/content/reference/rsc/use-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Server Functions are exposed server endpoints and can be called anywhere in clie

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.

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

Expand All @@ -190,7 +190,9 @@ function LikeButton() {
const onClick = () => {
startTransition(async () => {
const currentCount = await incrementLike();
setLikeCount(currentCount);
startTransition(() => {
setLikeCount(currentCount);
});
});
};

Expand Down
Loading