Does tanstack form work well with discriminated unions? #1623
Unanswered
virtuallyunknown
asked this question in
Q&A
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.
-
Greetings.
I would like to ask, does Tanstack Form handle advanced form requirements such as having data which is a discriminated union. For example:
I need to express this relation in a dynamic form, where the animal type is a
select
element which changes the form type, and different fields are rendered depending on the selected animal. If adog
is selected, we need<input type="text" name="bark" />
, if abird
is selected, we need<input type="text" name="bark" />
and checkboxes that add/remove colors from thecolors
array.I've been trying to do this with RHF for the last 2 days and I've encountered all sorts of issues. You can see what I am trying to build in this codesandbox. This particular example works, but there have been more issues I've discovered since, in particular about
watch
anduseWatch
having straight out incorrect type definitions provided by the library itself.So, the question is whether or not Tanstack form is better suited for this task. Researching about this online yielded surprisingly few results, and there aren't any examples in the docs that cover this particular use case.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions