r/reactjs • u/ItsAllInYourHead • May 19 '26
Discussion We've GOT to talk about TanStack Form...
I decided to finally give TanStack Form a try. All of their other libraries by them that I've used have been great, and I've heard nothing but good things about it. And a decent amount of people seem to be using in production.
But I immediately hit what I would think would be a HUGE problem with ANY form library: if you submit your form to your server, and it returns an error - how do you surface that in the form library.
Apparently the answer is: you don't?
There is an onSubmit function you pass to useForm. This is where you make your network request or whatever. But what happens if that fails? There appears to be no way to deal with that! You can manually set errors, apparently, but the form's isSubmitSuccessful property is going to still be true. And the user won't be able to resubmit unless they change a field (so, for example, if the network request fails for an unrelated reason, you can't just resubmit).
It's all very bizarre to me. How is anyone using this in production? I'm just completely baffled by this. Who is realistically using this? And who are these people saying it's ready for production use?
Here's a bunch of issues/discussions around it:
32
u/ZeFeXi May 19 '26 edited May 19 '26
Does react-hook-form handle this any better?
9
u/gaaaavgavgav May 19 '26
Should a form library even be required to handle this? Why not just intercept the response yourself and act accordingly? Seems like this was an intentional API choice by them, after all, it's still a client-side library at the end of the day.
135
u/Crutchcorn May 19 '26
Hey all, I'm Corbin — lead maintainer of TanStack Form.
I'm not going to front with you all: We broadly agree that this is an issue.
Overarchingly, while many of our users have been satisfied with `onSubmitAsync`, there's a clear gap here that needs to be addressed. We were going to wait until Form v2 to address this but given the feedback here we're going to backport our proposed API to the current version of Form:
https://github.com/TanStack/form/issues/2188
We will be working to get this implemented very quickly.
> FWIW we were only waiting on v2 because I personally was unaware the response would be so strongly in favor of needing this sooner. We always try to listen to our community so please don't stop letting us know what you need.
Honestly, we're rethinking a lot about how validation works in TanStack Form v2. We want to get feedback from some partners before we open up comms further about that, I will mildly tease that v2 should have:
- Schema-based transforms in `onSubmit`
- Even more flexibility with validators
- Better mix-n-match behavior with `onChange`, `onBlur`, and more
- Substantially faster performance (rendering 10,000 DOM input nodes is a breeze for v2 in our testing)
- Likely better type inferencing on `errors`
- Possibly a smaller bundle size
This is all to say that we're here, we're listening, and we're working hard on making TanStack Form the best solution out there for all form-related needs.
23
u/opentabs-dev May 19 '26
yeah ran into this exact thing last month. workaround that mostly fixed it for me: in your
onSubmitcatch block, callform.setFieldMeta(name, m => ({...m, errorMap: {...m.errorMap, onServer: msg}}))for each server error, and passcanSubmitWhenInvalid: trueto useForm so the form isn't locked after the first failure. for the resubmit-after-failure thing you also have to manuallyform.reset(values, {keepDefaultValues: true})on retry or it stays in the submitted-with-errors state. it's gross but it works until they actually fix it. the open discussion you linked (#623) does say maintainers acknowledged it, just no eta.5
u/nayeem14 May 19 '26
My question would be this - why should a client state library deal with network interactivity?
16
u/adfawf3f3f32a May 19 '26 edited May 19 '26
I use tanstack-query for the mutations so I made a
useFormMutationhook which try / catches itsmutateAsyncso I can catch api errors, mutate them, and add them to the form's errors.There's extra there but the nuts and bolts is catching the tanstack-query mutation then the form's setFieldMeta with the errors. This matches the form's fields to the api errors if they match and hold onto the unmatched ones which i show in a error summary above the form. The ones that do match fields get added to the form's errors and are displayed below the fields / wired up to all the aria stuff and displayed in the error summary as links that focus the field. It's basically everything I ever wanted in a form system.
5
u/rm-rf-npr NextJS App Router May 19 '26
Yup, use everything by Tanner, but forms is not it IMO. It's why we use React Hook Forms still. I remember testing it out, I wanted to split my form up in multiple components, but couldn't... no way to do that with something like useFormContext.
It's the disabled child In a family of geniuses.
3
u/haswalter May 19 '26
I’ve just migrated back to RHF after trying tanstack form. I use tanstack libraries as much as possible because they just work and generally the DX is great but fork feels like it’s completely out of style for a tanstack library.
The biggest issue I hit, or pain point, was when trying to create components to use with the form and the amount of boilerplate required not to mention to pass the form around the generic needs 15!!!! Params!
RHF is generally effortless with well thought out types that are easy to use / extend and to be honest I much prefer creating the form and handling my logic in separate more explicit code blocks.
2
u/coldfeetbot May 19 '26
Tanner what are ya doing, Tanner please stahp
1
u/AgileRice3753 May 19 '26 edited May 19 '26
Just show an inline alert on the form if you get a submission error. Should have nothing to do with Tanstack/react-hook-form. They solve inline validation and state, not server error handling.
You can use async validators if you want to validate by calling the backend (for example looking up to make sure a username isn’t taken).
IMO, client side inline validation errors should be shown on the form controls so the user knows what to adjust. For API call error handling, come up with a consistent pattern across the app. I usually do alerts with consistent messaging (changing the subject for each), possible steps the user can take to resolve it and how to get in touch if it persists.
As a side note, we use react hook form and find it really nice to use.
0
u/franciscopresencia May 19 '26
I built a small form library after having worked on hundreds of forms and this was a key consideration. While it's not perfect (missing per-field custom errors/validation), it supports 4 major error handling very seamlessly:
https://form-mate.dev/#form-error
0
u/strblr May 19 '26
TanStack is often overengineered and impractical. The thing they got right is Query, and even that feels weird (ensureQueryData, prefetchQuery, fetchQuery, etc). I know that's probably an unpopular opinion here.
-11
u/lightfarming May 19 '26
seems like you didn’t look very well.
https://tanstack.com/form/latest/docs/framework/react/guides/validation
it has a way to set field level errors from the form’s validators.
-7
u/alien3d May 19 '26
the real word is , it is supported by back end . c# have its own cancellation token , go have cancellation context and php is non . The only way is to use abort controller if existed in tanstack form .
It is not easy as , you would you want continue process if somebody change page ? , failure no problem if you had transaction.
-21
u/Lower-Excuse-6558 May 19 '26
Didn’t tanstack just distribute a large binder of malware due to overlooked GitHub tokens issues/loopholes?
ETA
https://tanstack.com/blog/npm-supply-chain-compromise-postmortem
8
u/[deleted] May 19 '26
[removed] — view removed comment