🎣 Form validation with React Hooks WITHOUT a library - The complete guide
A DYI tutorial for form validation
I’m back with a new article that has now been two weeks in the making.
Initially, I wanted to release this one last week, but I decided to take some more time to make sure that it lives up to its title 😊.
The topic is form validation in React.
As frontend developers, creating forms is one of the most common things we need to do, and yet, at least in my case, I never took the time to think about whether or not I approach this topic with enough efficiency.
I always made things work, but my code wasn’t always very reusable.
Since React Hooks' introduction, creating small, stateful code snippets that you can reuse in any component has become incredibly easy, so I decided to apply this notion to managing and validating forms.
In this article, I walk you through the process of creating a hook that you can use for managing forms without the use of a library.
I also explain how to create the TypeScript definitions for this hook, making it strongly typed for any form you use this for.
Do you have other preferences when managing React forms? Let me know by responding to this email :)
Thanks for reading, and have a nice week!