DEV Community

Pablo Yeverino
Pablo Yeverino

Posted on

1

Cleaner React validations

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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (1)

Collapse
 
cuginoale profile image
Alessio Carnevale

I am proposing a simple and clean approach to form validation here:
dev.to/cuginoale/form-validationsu...

Please let me know what you think! :)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay