Which React Form Library Should You Use in Your App in 2020?
Tags: react, javascript
Published: 2019-11-22 10:54:47

A few days ago we posted a poll on our [ReactEurope](https://www.react-europe.org) [twitter](https://twitter.com/ReactEurope) asking people which form libraries they would use if they were to start a new project.
The results unsurprisingly reflected npm download stats with formik ahead but what npm numbers don't show is that almost as many users do not use any library at all and just rely on react hooks and lifecycle functions.


{% twitter 1196160911985324040 %}


[**formik**](https://github.com/jaredpalmer/formik) is the dominant one, it relies on react to manage forms while [**final-form**](https://github.com/final-form/react-final-form) can be used without it and makes use of subscriptions, it is also about half the size. Both formik and final-form users answered they were very happy with both so feel free to pick whichever, formik is bigger (14.7KB) compared to final-form (7.6KB) but formik has great support for react native and some cool features like managing low priority updates using react’s scheduler.

[**react-hook-form**](https://react-hook-form.com/) is also pretty neat, as its name indicates it was built post React hooks release and is really optimized for them and written in TypeScript, it will also make you write a little less code than the other two libraries especially for validation which is always a good thing. It also has benchmarks on its site showing it more performant than the competition though you always need to take these with a grain of salt. However, it is still new and some of its design decisions make it [incompatible](https://github.com/mui-org/material-ui/issues/17018#issuecomment-523679702) with a popular library such as MaterialUI (though there are [workarounds](https://github.com/react-hook-form/react-hook-form-input) being worked on).

There is also [**react-form**](https://github.com/tannerlinsley/react-form) which was also written with hooks in mind and support all the features you would expect from a form library including cool memoization for frequent and fast rerenders. It is also ridiculously small with just 4.5KB!

These 4 libs would be the main big ones however there are a few cool extra ones that deserve a mention:

[**unform**](https://github.com/Rocketseat/unform) which has amazing support for uncontrolled form structures.

[**react-jsonschema-form**](https://github.com/rjsf-team/react-jsonschema-form) if you need dynamic form generation, this library will generate a form for you using json, no need to write any code.

[**frontier-forms**](https://frontier-forms.dev/) also generates forms for you but based on your GraphQL mutations. That is to say, you just pass it a mutation query and it generates a form for you which is pretty cool. And because it makes use of final-form you get all the form state management and validation on top. You can watch a demo of it here from [last year’s edition](https://www.youtube.com/watch?v=Ovg9CYwWFBM).

All that being said, the elephant in the room here is that close to 40% of respondents said they did not use any library and David Piano who wrote the great [xstate](https://github.com/davidkpiano/xstate) state machine lib and sceptic of such form libraries suggested just using useReducer and useEffect instead which is similar to how it’s done in [ReasonML](https://reasonml.github.io/reason-react/docs/en/state-actions-reducer#docsNav).

{% twitter 1196224209359450112 %}

If you’re not familiar with either useReducer or ReasonML, think of it as a local redux for your form, in other words, a reducer to which you can dispatch actions triggered by your form.

You can see some nice examples of using useReducer [here](https://medium.com/javascript-in-plain-english/react-controlled-forms-with-hooks-538762aab935), [here](https://codeburst.io/colocating-side-effects-with-actions-using-usereducer-490368c96f77) and [there](https://www.reddit.com/r/reactjs/comments/bw96or/using_the_usereducer_hook_for_managing_my_forms/?ref=readnext).

However, people were quick to ask David how would we deal with the other issues that form libraries take care of such as validation, errors and more.

{% twitter 1196228691585617920 %}

There doesn’t seem to be a concentius on that part for now.

**Conclusion:**

If you want to play it safe, go with one of the big four mentioned above, they cover more than 90% of use cases and offer a great DX. If you’re feeling a bit adventurous, you can try one of the extra ones mentioned.

If your forms get very complex, you may regret picking a library and wish you followed David’s advice by just using useReducer. However, most people are happy using these libraries even on big projects as people reported in our original twitter thread.

If you want to learn more about this topic we’re happy to say that Erik Rasmussen, the author of final-form will do a [workshop that will teach you how to build modern forms in the three main ways mentioned above](https://www.react-europe.org/#slot-2039-modern-forms-in-react):

1.  by just using useState
2.  by using useReducer and useEffect
3.  by using a library that smooths the process of dealing with validation, errors and more.

How about you? Feel free to comment which is your prefered way. By the way, if you’re in the process of writing your own form library that you think would bring the best of both worlds (useReducer+validation etc) or even something different and you want to show it at the conference, [feel free to send us a proposal on our call for paper](https://checkout.eventlama.com/#/events/reacteurope-2020/cfp), we’d love to read about it!