Cleaner React validations

yeeiodev profile image Pablo Yev ・1 min read

10/28 - Yesterday I finished an assignment related to a 'Change phone-number form and it looks like this:

Alt Text

So, to validate I need to check every change of the Input fields in order to enable or disable the button... easy right??

Just for context, I'm using useState hooks for each value of the field and another one to the enabling state of the button. Also, I'm managing state with MobX, so the user's current phone number and country code properties of userStore. Hopefully it's enough context for the next snippets.

Alt Text

After some really nice PR review, my code was simplified to this:

Alt Text

I really like the approach because is pretty much self explanatory and a little bit cleaner.

What am I doing today:

  • Start doing push ups each two brakes. That means that if I take a brake every hour, I should do 4 rounds of push-ups a day. What do you thing??
  • Take at least 30 minutes of video editing course.

If you got all the way over here, I really appreciate it!!

If you want to, follow me on Twitter


Editor guide