Front End Engineers work a lot with forms and with the complexity of apps we need powered forms to help us managing the form state, form validation with nested levels, form verbosity.
Formik comes to solve all these problems.
Now we have a new library React Hook Form was released to compete.
How easy is it to solve complex form constructs?
For Complex Features "Nested array" or "nested objects"
Formik handles it perfectly with validation on different events like onblur - onchange.
react-hook-form handle it but the validation of nested fields with "onblur" or "onchange" needs some works.
For simplicity, I see formik win cause it handles more stuff behind without the need to add it by yourself.
Controlled & UnControlled Component
Formik support Only Controlled Component but React-hook-form support both of them.
is one that takes its current value through props and notifies changes through callbacks like onChange. A parent component "controls" it by handling the callback and managing its own state and passing the new values as props to the controlled component.
Controlled Component with RHF
Controlled Component with Formik
is one that stores its own state internally, and you query the DOM using a ref to find its current value when you need it.
|one-time value retrieval (e.g. on submit)||✅||✅|
|validating on submit||✅||✅|
|conditionally disabling submit button||❌||✅|
|several inputs for one piece of data||❌||✅|
With React Hook Form watch Function help you to watch specified inputs and return their values to determine what to render.
With Formik watching all fields enabled by default so you can remove or add fields depend on values prop.
With React Hook Form Read Form Values inside events.
With Formik you can read form values with values prop.
Compare Both with Examples, See Formik VS React Hook Form Part II