DEV Community

Discussion on: How to Forms with React and Typescript

 
steida profile image
Daniel Steigerwald • Edited

Don't get me wrong, I know both Formik and Yup. Yup does not support branded types nor option nor any other fp-ts types. But thank you for a comment, I should highlight it.

Anyway, please check the first five minutes of this talk youtube.com/watch?v=PLFl95c-IiU to understand my motivation. It's about F#, but with io-ts, we can model a much stricter schema in a similar way. For example, string which is only the email, not any string, or an array with the first item of type A and second optional type B. We can express a lot of business rules. Email and Verified email (both strings) with type safety. Hopefully, soon you realize that plain string or number types are close to any. I recommend you try both examples.

As for useForm. Once we use io-ts, for the reasons I mentioned, we can not use Formik, and honestly, that hook is so simple yet powerful, that we don't have to. There are also other design decisions why I did not make Formik clone, but that's for another blog post.