The React ecosystem is lush with libraries, articles, videos, and more resources for every web development topic you could imagine. However, over t...
For further actions, you may consider blocking this person and/or reporting abuse
Or even better, use TypeScript, and use Object.fromEntries:
J
Great addition! Thank you! 🙏
When using React, I've not found a use case yet that React Hook Form didn't satisfy and make my life 1000x simpler
You've swayed me away from using controlled fields with state for form data, completely agreed with your rationale for using uncontrolled inputs where possible:
This is my first time hearing of the FormData API, I'll definitely be using that going forward!
Would love to read a follow up where you discuss more about how React-Hook-Form fits into the picture. Great article dude, thanks for taking the time to write it
I nearly didn't read this article thinking I knew enough about forms. 😏
I'm very glad I did. Really great perspective and will definitely make me revisit how I implement forms in future projects.
More broadly, really well written article. 👍
Perfect balance of being concise and providing detail.
Excellent article, it helped me a lot. In my job we created dozens of controlled forms, and it was cumbersome and hard at moments, with a lot of bug potential. I didn't use uncontrolled because I didn't know about new FormData(). The way you manage uncontrolled forms is definitely the way, managing controlled inputs only when needed
I use class components because instances of such components exist. Each form consists of forms, forms of forms, ... and so on. Each form has a public method
get() {return {dataA: refs.formA.get(), dataB: refs.formB.get(), dataC: ":)"}}
that will return form data that was collected from child forms by calling get().This simple solution allows me to create very large and complex shapes. Unfortunately, this approach is not possible on functional components
I really like this approach. The question is, how do you handle more complex forms with nested data in arrays? Something like:
{ name: "James", hobbies: [{name: "football"...}, {name....}]}
Besides FormData we can also make use of the form submit event and access input elements like => event.target.elements.[inputID] or event.target.elements.[inputName]
And if you want to send form data to your email without touching the server code you can do it with mailik.dev/
It was quite useful, thank you
This looks good and i definitely will try to use this approach to reduce complexity on my side projects.
Nice article . great info, Thanks for sharing
Thanks for sharing 🙌
Very good writeup! 😎