DEV Community

Discussion on: React JS Web Site Example (Almost like real life).

Collapse
 
caseyreeddev profile image
Casey Reed

I'm fairly new to React, but is there a reason you use document.getElementById() in your component.js rather than using the ref attribute? For example, adding something like ref={(input) => { this.textInput = input; }} onto the input in your JSX.

Fantastic article, by the way! Will certainly be reading and re-reading down the line.

Collapse
 
svinci profile image
Sebastian G. Vinci

The recommended way is to use event handlers.

Having a function defined as function onChange(event), and passing it to the element as onChange={onChange}.

The thing here is that I didn't want to make it more complex, because it's just one input and one button, so that did the trick. If there were more elements involved, with a more complex form, I would've handled it using event handlers.

You gave me an idea, I'll try to write a post on how to handle complex forms during this week!

Thanks for pointing that out!
Regards.