Create a Controlled Form, can't get the problem

Tell us what’s happening:
Very cut and dry, I don’t understand react and I don’t get why the test aren’t passing.
Please help, thanks in advance.

Your code so far


class MyForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      input: '',
      submit: ''
    };
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }
  handleChange(event) {
    this.setState({
      input: event.target.value
    });
  }
  handleSubmit(event) {
  event.preventDefault();
  this.setState({
    input: '',
    submit: this.state.input
  });

  }
  render() {
    return (
      <div>
        <form onSubmit={this.handleSubmit}>
          { /* change code below this line */ }
<input type="text" value={this.state.input} OnChange = {this.handleChange} />
          { /* change code above this line */ }
          <button type='submit'>Submit!</button>
        </form>
        { /* change code below this line */ }
<h1> {this.state.input} </h1>
        { /* change code above this line */ }
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.94.

Link to the challenge:

You have a couple of problems:

  • OnChange = {this.handleChange} → The property is called onChange :stuck_out_tongue:
  • <h1> {this.state.input} </h1> → The challenge says:

The h1 header should render the value of the submit field from the component’s state

  • <h1> {this.state.input} </h1> → One thing you could have problem with: remove the spaces before/after curly braces^^

React is hard for everyone when starting, hold on! :+1:

1 Like

Thanks, that was enough to figure it out

1 Like