TanStackT
TanStack10mo ago
2 replies
rubber-blue

Form composition

Hello, how do you refactor the form and submissions? Currently i have page with form and useAppForm hook where i have onSubmit actions. something like this

//page
const form = useAppForm({ ...formOpts, onSubmit: async({value}) => { const response= await submit(value) if(response){ //other stuff setResult(response) toast("success")} } })


And i have config formOpts file with types, zod and validation with another onSubmit

const formSchema = z.object({ ... }) export const formOpts = formOptions({ defaultValues: { ... }, validators: { onSubmit: formSchema, }, })

And form component which is just form and fields

What is the best way people do forms in tanstack? I think about moving form validation from the page to custom hook that will return form, submit and result values
Was this page helpful?