Summary
The updateName Server Function is defined as updateName(name), but the page later uses it as a direct form action and with useActionState. These usages pass different arguments, so the examples cannot work with the shown function.
Page
https://react.dev/reference/rsc/server-functions
Details
The page defines:
export async function updateName(name) {
if (!name) {
return {error: 'Name is required'};
}
await db.users.updateName(name);
}
There are several inconsistencies/mistakes:
-
In “Server Functions with Actions”, the input does not update the name state, so updateName(name) always receives ''.
-
On success, updateName returns undefined, but the client destructures {error} from its result.
-
When passed to <form action={updateName}>, React calls updateName with FormData, not a string.
-
When passed to useActionState, React calls it with (previousState, FormData), and it must consistently return the next state.
The examples should define a Server Function with the correct parameters and return value for each usage.
Summary
The
updateNameServer Function is defined asupdateName(name), but the page later uses it as a direct form action and withuseActionState. These usages pass different arguments, so the examples cannot work with the shown function.Page
https://react.dev/reference/rsc/server-functions
Details
The page defines:
There are several inconsistencies/mistakes:
In “Server Functions with Actions”, the input does not update the
namestate, soupdateName(name)always receives''.On success,
updateNamereturnsundefined, but the client destructures{error}from its result.When passed to
<form action={updateName}>, React callsupdateNamewithFormData, not a string.When passed to
useActionState, React calls it with(previousState, FormData), and it must consistently return the next state.The examples should define a Server Function with the correct parameters and return value for each usage.