life's easier if you just use a single state object for your whole form, and a changeHandler that uses es6 dynamic properties. the switch and custom useStates get annoying real quick.
this will allow you to implicitly handle change for any form input, via its name attribute.
note that for fields that dont use value (like checkboxes) you'll have to do some more handling
you can also pass in a default state to the useState, or type it in typescript like that.
My name is Adrian; currently a recent graduate of the Flatiron Software Engineering program. Broadening my knowledge base through posting and reading alike.
life's easier if you just use a single state object for your whole form, and a changeHandler that uses es6 dynamic properties. the switch and custom useStates get annoying real quick.
not the best way to approach formstate
A link so i can learn more about this other approach please?
a simple example, to get you started
this will allow you to implicitly handle change for any form input, via its name attribute.
note that for fields that dont use
value
(like checkboxes) you'll have to do some more handlingyou can also pass in a default state to the
useState
, or type it in typescript like that.Aw ok thanks for replied
Thanks for taking the time to read the article! I understand where you're coming from but opted for this approach purely by preference.
I appreciate your input.