Order of Server Action arguments when used with/without useFormState
#56221
Unanswered
robertwbradford
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm curious about the order of arguments in a Server Action function. The
formDataargument "moves" when the function is then used withuseFormState.For example, currently in https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations#server-only-forms it shows a basic example like this:
However, later in the page at https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations#error-handling it shows an Error Handling example with the following where
formDataneeds to move to the second argument:This means when we going to use our Server Action along with
useFormState, we need to change its signature. This threw me off the first time trying to useuseFormState.From a reusability perspective, when someone creates a Server Action function, they don't necessarily know where it is going to be consumed. If one form decides to use
useFormStatewhile another does not, we run into problems.I don't see any discussion in the React PRs about the order of arguments. I get that
useFormStateis creating a different function as the second item in its returned array, but I'm wondering if it would be more ergonomic to swapprevStateandformData. Would consumers be usingformDatamore thanprevState?Anyway, since this is a
react-domfeature, the discussion may belong elsewhere, but I wasn't sure where to bring this up.Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions