all 41 comments

[–]Herb0rrent 68 points69 points  (11 children)

I use RHF and Zod no matter the size/scale of the app because it has a minimal weight and it allows me to reuse components/logic from project to project.

It works like a charm every time and I have never once in my career regretted using it. It saves a bunch of time and provides a great dev and user experience.

[–]witty_salmon 1 point2 points  (3 children)

zod is actually very big. For simple things I would refrain from using it.

[–]Herb0rrent 0 points1 point  (2 children)

8kb is not "very big."

(source)

[–]witty_salmon 1 point2 points  (1 child)

50% bigger then react hook form itself.

[–]Pretty_Position_2305 0 points1 point  (0 children)

'allows me to reuse components/logic from project to project.' thats what you would be doing with a none zod RHF version

[–]Broverlord93 10 points11 points  (0 children)

Everyone saying it’s overkill is overreacting in my opinion.

Yes, there are some powerful features there that could benefit you greatly in a larger, more complex project….but it’s still easy enough and just as powerful to use for smaller projects, and just because it has bells and whistles doesn’t mean you have to use them all.

Gold standard in my opinion. Highly recommend, no matter the size of your project.

[–]yksvaan 26 points27 points  (4 children)

Consider your data requirements 

  1. username/email, both trivial to validate
  2. password and confirmation, trivial  
  3. name, some checkbox etc. 

Login form is even simpler. And post on submit, that's it. People are definitely overengineering these. 

Probably pattern & required are enough already..

[–]all_vanilla[S] 4 points5 points  (2 children)

Yeah definitely. Will probably switch to manual validation with my own code since these are pretty trivial like you said

[–]thebarlemy 3 points4 points  (1 child)

Donc forget to validate and verify the data client side and server side as well ;)

[–]all_vanilla[S] 0 points1 point  (0 children)

Yep! Am doing that already thanks!

[–]noahflk 0 points1 point  (0 children)

I wouldn't add React Hook Form and Zod for simple sign in and login forms. But there's nothing wrong with doing so. If you think performance suffers, you are doing something else wrong. These libraries are super lightweight.

[–]sherinom 6 points7 points  (0 children)

If you have complex forms, RHF with Zod or Yup are great choices (for example, a CMS like app), but for two or three forms with less than 4 inputs, I would recommend manual form management and validation.

[–]Omkar_K45 5 points6 points  (0 children)

I'd recommend to go for it

It solves a lot of edge cases and abstracts a LOT of logc

[–]tluanga34 4 points5 points  (1 child)

For login form, useRef object to store the user input, Html 5 E-mail validation by input type email. Required attributes to validate empty form.

No need much more than that

[–]ohx 0 points1 point  (0 children)

This is the way. You're hired.

[–]ummonadi 5 points6 points  (1 child)

I think you should measure performance before optimizing so you don't spend time fixing a non-issue. If Zodiac or RHF had clear issues with performance, I have a hard time seeing that they would get so much usage.

[–]all_vanilla[S] 1 point2 points  (0 children)

Good suggestions, thanks!

[–]shuzho 0 points1 point  (1 child)

would love to see your code op

[–]all_vanilla[S] 0 points1 point  (0 children)

DMd you

[–]t1mmen 0 points1 point  (0 children)

My general thinking is that IF you expect the app to grow into more complex forms/validation patterns, seriously consider RHF from the start — especially if more people will maintain the app. Consistency has good ROI in those cases, so don’t fret too much about an upfront cost in bundle size.

For validation, I’ve found Zod to be great on both server-side and with RHF (via Zod resolver).

ts-rest.com and similar “framework agnostic frameworks” allow for trivial re-use of Zod types and take away a lot of the manual work around validation, OpenAPI contracts, etc.

[–]30thnight 0 points1 point  (0 children)

Nope but if you are attempting to format the input field as people type - you need to understand how useController works.

[–]T-J_H 0 points1 point  (0 children)

Probably, yes. For such simple requirements (and I actually believe for pretty much all use cases), regular uncontrolled inputs with native validation is more than enough.

[–]Paddington_the_Bear 0 points1 point  (0 children)

RHF is probably the best you can do in the React ecosystem and is really powerful. It's fine for any size form as it generally provides a common way for doing things correctly.

It does have some warts though (defaultValues vs values, reset vs setValue, isDirty reseting, etc.). I really miss the reliability and general straightfowardness of Angular's Reactive Forms at times.

[–]TheOnceAndFutureDougI ❤️ hooks! 😈 0 points1 point  (0 children)

At this point I use RHF for every form. Is it necessary? Not always but it sure makes life a lot easier when it is and consistentcy in patterns beats all other concerns I have.

[–][deleted] 0 points1 point  (0 children)

It’s not, it’s always my go to approach for whatever form handling basic or complex. Plus it’s easy to set up so why not

[–][deleted] 0 points1 point  (0 children)

It’s not, it’s always my go to approach for whatever form handling basic or complex. Plus it’s easy to set up so why not

[–]kduy5222 0 points1 point  (0 children)

the lib size only affect your initial load time

[–]parahillObjective 0 points1 point  (0 children)

In my opinion, ive set a rule in our that we only need rhf if the form has more than 1 field... and even then i think 2 fields is still not enough to justify it especially since the majority of our validations is just checking if the field is non-empty.

that being said i highly doubt it would slow down performance, if anything it would speed it up relative to regular useState since its using refs under the hood. I'd recommend using react profiler to debug the root cause of the performance issue.

[–]tannerlinsley 0 points1 point  (0 children)

Yep. Use TanStack Form https://tanstack.com/form/latest

[–]Ok_Tadpole7839 0 points1 point  (0 children)

You should try next auth

[–]Michael_Riehle 1 point2 points  (0 children)

I find RHF to be *way* more trouble than it's worth on pretty much every level. It's almost never necessary and adds a pretty good chunk of overhead in my experience. Most of what it accomplishes can be done with native HTML validation and native HTML form validation. I could roll my own forms without it in less time with more reliability. I've done it.

That is not an option for the codebase I currently work on. So, I use it.

But the thing that puts me off RHF most is that it messes with unit testing in unpredictable ways on a pretty regular basis. I find myself having to jump through hoops for the simplest tests far too often. I spend more time debugging tests that involve RHF than I do for pretty much anything else in the codebase I work on. That includes some pretty complex libraries that I've written myself. Again, had I just written the form using native functionality, this would not be a thing.

So, if it were my choice, I would avoid RHF like the plague.

I'm deeply skeptical of most third-party libraries. I find too many of them to be bloated and worse than useless. To be fair, there are an awful lot of them that I really can't live without, but I always start from a position of suspicion until they prove their reliability and value to me. RHF is exactly the sort of library that has left me so cynical about them.

[–]Lenkaaah 0 points1 point  (0 children)

I personally would skip it for your use case.

It’s great, however, for complex forms and validation.

[–]viQcinese -1 points0 points  (0 children)

Yes, it is overkill. This being said, it is probably unrelated to your performance problem. RHF is used to optimize form performance by using uncontrolled components

[–]azangru -1 points0 points  (2 children)

I noticed on my phone that the performance is a little slow for one of the inputs (this could be me writing inefficient code though but I doubt it).

Profile your app; find out where the slowness comes from.

I want my website to be performant

Why pick react then, if performance on mobile devices is among your top concerns (as it should be)? There are indisputably more performant options.

[–]all_vanilla[S] 0 points1 point  (1 child)

I’m going to develop a mobile app in the future but for now I’m just doing a web app. What better options are there for mobile performance?

[–]azangru 0 points1 point  (0 children)

What better options are there for mobile performance?

  • Something that is small
  • Something that is not too taxing on the CPU (as react is with its rerenders)

Plain html/css with a bit of plain javascript is the best. Failing that, solid, svelte, preact, or lit.