Create-a-controlled-input

Create-a-controlled-input
0

#1

Tell us what’s happening:
Why the last one is not passing the tes.
Typing in the input element should update the state and the value of the input, and the p element should render this state as you type.

Your code so far


class ControlledInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      input: ''
    };
    // change code below this line
    this.handleChange = this.handleChange.bind(this)
    // change code above this line
  }
  // change code below this line
  handleChange(e) {
    this.setState({
      input: e.target.value
    })
  }
  // change code above this line
  render() {
    return (
      <div>
        { /* change code below this line */}
        <input type="text" onChange={this.handleChange} value={this.state.value} />
        { /* change code above this line */}
        <h4>Controlled Input:{this.state.input}</h4>
        <p>{this.state.input}</p>
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Link to the challenge:


#2

Finally!, I am able to crack the challenge

<input type="text" onChange={this.handleChange} value={this.state.input} />


#3

Thanks! I just had the same issue and this fixed it. It could be more directly mentioned in the lesson instruction.


#4

I had the same issue! many thanks @Randore


#5

Cool, it helps me pass the test. But I have one question here:

onChange={this.handleChange}

Why we don’t need a parameter for handleChange here? Since the method handleChange needs one parameter when it is defined. Please help me with this.