Skip to content

docs: fix Server Functions code examples with incompatible signatures - #8583

Open
yash2277-ctrl wants to merge 1 commit into
reactjs:mainfrom
yash2277-ctrl:docs/fix-server-functions-examples
Open

docs: fix Server Functions code examples with incompatible signatures#8583
yash2277-ctrl wants to merge 1 commit into
reactjs:mainfrom
yash2277-ctrl:docs/fix-server-functions-examples

Conversation

@yash2277-ctrl

Copy link
Copy Markdown

Summary

This PR fixes broken code examples in the Server Functions documentation where function signatures don't match their usage patterns.

Fixes

Closes #8537

Problems Fixed

1. Missing return value

The updateName function returned undefined on success, but client code destructured {error} from the result.

2. Form action signature mismatch

When passed to

, React calls it with FormData, not a string parameter.

3. useActionState signature mismatch

When used with useActionState, the function must accept (previousState, formData) and consistently return the next state.

4. Input not controlled

The input field didn't have value or onChange, so the name state was always empty.

Changes Made

Example 1: Server Functions with Actions

  • Fixed updateName to return {error: null} on success
  • Added value and onChange to input to make it controlled
  • Simplified error handling logic

Example 2: Server Functions with Form Actions

  • Created updateNameForm function that accepts FormData
  • Extracts name using formData.get('name')
  • Returns proper {error: null} on success

Example 3: Server Functions with useActionState

  • Created updateNameAction with (previousState, formData) signature
  • Extracts name using formData.get('name')
  • Returns consistent state shape

Impact

Type of Change

Fixes reactjs#8537%0A%0AThis commit fixes multiple issues with the Server Functions examples:%0A%0A1. First example (Actions): Added return value {error: null} on success and fixed input to be controlled with value/onChange%0A%0A2. Second example (Form Actions): Renamed to updateNameForm and fixed to accept FormData parameter instead of string, matching React 19 form action behavior%0A%0A3. Third example (useActionState): Renamed to updateNameAction and fixed to accept (previousState, formData) parameters as required by useActionState%0A%0AAll examples now have correct function signatures matching their usage context.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Mistakes]: Server Functions examples use incompatible action signatures

1 participant