I just completed the “Create a Controlled Input” exercise in the React track using the code below. However, I do not understand how this code passes the tests due to the event
parameter. The argument is not declared in the render
method when the handleChange
method is called, and as far as I can see, there is nothing that connects this.state.input
to event.target.value
.
If anyone could clarify how the connection is being made to me I would be very grateful.
jsx
class ControlledInput extends React.Component {
constructor(props) {
super(props);
this.state = {
input: ''
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({
input: event.target.value
});
}
render() {
return (
<div>
<input value={this.state.input} onChange={this.handleChange}/>
<h4>Controlled Input:</h4>
<p>{this.state.input}</p>
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61
.
Challenge: Create a Controlled Input
Link to the challenge: