You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// action.ts'use server'// Notice the import path is different from the clientimport{createServerValidate}from'@tanstack/react-form/nextjs'import{formOpts}from'./shared-code'// Create the server action that will infer the types of the form from `formOpts`constserverValidate=createServerValidate({
...formOpts,onServerValidate: ({ value })=>{if(value.age<12){return'Server validation: You must be at least 12 to sign up'}},})exportdefaultasyncfunctionsomeAction(prev: unknown,formData: FormData){returnawaitserverValidate(formData)}
Which doesn't give a clear indication of when an error is validated or not to:
// action.ts'use server'// Notice the import path is different from the clientimport{createServerValidate,ServerValidateError}from'@tanstack/react-form/nextjs'import{formOpts}from'./shared-code'// Create the server action that will infer the types of the form from `formOpts`constserverValidate=createServerValidate({
...formOpts,onServerValidate: ({ value })=>{if(value.age<12){return'Server validation: You must be at least 12 to sign up'}},})exportdefaultasyncfunctionsomeAction(prev: unknown,formData: FormData){try{awaitserverValidate(formData)}catch(e){if(einstanceofServerValidateError){returne.formState;}}}
This makes it much more clear how to handle the next steps and error handling, encourages defensive behavior, and more.
The text was updated successfully, but these errors were encountered:
Ideally the API should move from:
Which doesn't give a clear indication of when an error is validated or not to:
This makes it much more clear how to handle the next steps and error handling, encourages defensive behavior, and more.
The text was updated successfully, but these errors were encountered: