Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 7, 2021 10:29 am GMT

Formik VS React Hook Form Part I

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.

Module Composition

Formik has nine dependencies
formik composition

React Hook Form has no dependencies
React Hook Form bundle

Controlled & UnControlled Component

Formik support Only Controlled Component but React-hook-form support both of them.

Controlled Component

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

Uncontrolled Component

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.

feature uncontrolled controlled
one-time value retrieval (e.g. on submit)
validating on submit
conditionally disabling submit button
several inputs for one piece of data
dynamic inputs


Re-Rendering

We want to avoid unnecessary re-render cycles as much as possible, as this could lead to major performance issues as an app grows.
image-rerender-formik & react-hook-form

Dependent Fields

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.

Events

With React Hook Form Read Form Values inside events.

note: getValues() will not trigger re-renders or subscribe to input changes.


With Formik you can read form values with values prop.

Summarize

feature formik react-hook-form
Size 12.6kB 5.2kB
Weekly Downloads 1,314,511 638,419
Dependencies 9 0
Open Issues 498 6
React Native
TypeScript
Class components
Clear documentation
Yup integration


Compare Both with Examples, See Formik VS React Hook Form Part II


Original Link: https://dev.to/doaashafik/formik-vs-react-hook-form-aei

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To