DEV Community

Discussion on: I was creating Forms the wrong way all along in React.js 🤔

Collapse
 
daaitch profile image
Philipp Renoth

Thanks for sharing, cool article. Especially the new FormData(e.target) part make things more easy.

My opinion: don't use "controlled components". If you have them, remove them and use the approach <form onSubmit={..}>. If you need validation, you can check input in onChange and use like setUsernameError(..) if you need to really render the component to show an error, but not every keyboard hit will make it render.
At least there are some libs for forms.

Collapse
 
kuvambhardwaj profile image
Kuvam Bhardwaj

Thanks for the comment, Philipp :)

Yes, you're right, and I personally use the same approach too, but I have seen in codebases, sometimes people like to use this
value{ x } onChange={e => setX(e.target.value)}

Thought might include it as well!