Accessing form values (React)
Tue Dec 26 2023 21:17:30 GMT+0000 (Coordinated Universal Time)
Saved by
@Marcelluki
// InfoForm.js
this.state = {
submitted: false,
userEmail: '', // we'll start this off as an empty string
};
//We can attach the onChange listener to our <input> element. This will be triggered every time a change is made inside our input. For example, if the user enters the string, 'pillow' inside of our input, onChange() will fire 6 times, one for each character inside the string.
// InfoForm.js
<input onChange={this.handleChange} className="infoForm-input" type="email" placeholder="Enter your email here"/>
//Finally, we'll need to create the handleChange() method itself:
// InfoForm.js
handleChange = (evt) => {
this.setState({ userEmail: evt.target.value });
};
content_copyCOPY
https://tripleten.com/trainer/web/lesson/9670babf-c9e3-44c3-8784-d5bc9efc6c34/
Comments