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.
I'm currently starting a project to apply something I just learned, but I will probably get bored in a couple days once I finish applying my learnings. It doesn't matter when you read this.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm fairly new to React, but is there a reason you use
document.getElementById()
in yourcomponent.js
rather than using theref
attribute? For example, adding something likeref={(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.
The recommended way is to use event handlers.
Having a function defined as
function onChange(event)
, and passing it to the element asonChange={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.