r/reactjs • • Dec 17 '23

Discussion Is react hook form overhyped?

I created a custom form validation hook.Its a simple hook and I felt I didn't needed react hook forms for just simple form validation. For simpe validation writing that much code and loading the whole library felt not right. Maybe I am wrong.

0 Upvotes

45 comments sorted by

View all comments

10

u/zephyrtr Dec 17 '23

A good exercise is try to answer this question for yourself: advocate for why you'd want to use RHF instead of a home-grown solution? Is "loading the whole library" (an extra 10kb) actually a problem? And if you can't come up with many reasons, you might not be especially exposed to the problem space. Also the RHF docs have lots of explanations for why something might be useful to you. If you haven't already, you might just read through it.

But the vast majority of apps are pretty simple CRUD apps, which are going to need to do two things:

  • Query and mutate server state

  • Help users build server requests that won't 400

So it shouldn't be surprising that most apps use two libraries to handle these very common, though not simple, needs. Some common needs:

  • Load and present a list of select options from the backend

  • Create a search bar that offers fuzzy-matched suggestions based on input

  • Prefill form inputs based on pre-existing values

  • Present inputs whose values have not been changed differently from those that have

  • Allow the backend to perform some complex validation the frontend cannot do, but present errors in the same way as frontend validation

  • Lock the form from being edited while waiting for a request response

  • On 201, update your query cache with a new record, so you don't have to completely reload your dataset

Could you do this without libs? Sure. Do you want to? Up to you. Personally, my answer is absolutely not. I've done it myself before and training others on what's going on and how to use reusable solutions is a giant pain. Even just maintaining docs eats up a lot of time that I don't have.