You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a Server Function outside a form, call the Server Function in a Transition, which allows you to display a loading indicator, show optimistic state updates, and handle unexpected errors
Which seems to suggest we should always wrap server functions in transitions when using them outside forms.
However here is example from docs without wrapping them in transitions:
// Server Component
import Button from './Button';
function EmptyNote () {
async function createNoteAction() {
// Server Function
'use server';
await db.notes.create();
}
return <Button onClick={createNoteAction}/>;
}
gmoniava
changed the title
[Typo]: Should server functions be wrapped in transitions or not? (conflicting info in the docs)
[Typo]: Should server functions be wrapped in transitions? (conflicting info in the docs)
Apr 11, 2025
gmoniava
changed the title
[Typo]: Should server functions be wrapped in transitions? (conflicting info in the docs)
[Suggestion]: Should server functions be wrapped in transitions? (conflicting info in the docs)
Apr 11, 2025
Summary
Here it says:
Which seems to suggest we should always wrap server functions in transitions when using them outside forms.
However here is example from docs without wrapping them in transitions:
Can docs make it clearer which to use?
Page
https://react.dev/reference/rsc/use-server#calling-a-server-function-outside-of-form
https://react.dev/reference/rsc/server-functions#creating-a-server-function-from-a-server-component
Suggestion
It should be made more clear whether both approaches are allowed or not and if allowed, what are pros cons of each.
PS. Initially I had opened this issue as typo/mistake but I guess Suggestion is a better fit, changed title, but old label remains.
The text was updated successfully, but these errors were encountered: