docs: fix Server Functions code examples with incompatible signatures - #8583
Open
yash2277-ctrl wants to merge 1 commit into
Open
docs: fix Server Functions code examples with incompatible signatures#8583yash2277-ctrl wants to merge 1 commit into
yash2277-ctrl wants to merge 1 commit into
Conversation
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.
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Example 2: Server Functions with Form Actions
Example 3: Server Functions with useActionState
Impact
Type of Change