Skip to content

[Mistakes]: Server Functions examples use incompatible action signatures #8537

Description

@smith558

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions