React - Create a Controlled Form

Tell us what’s happening:
Describe your issue in detail here.
kindly help check out my code, am getting the required render.

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) {
    // Change code below this line
    event.preventDefault()
    this.setState({
      submit: this.state.input
    });
    // Change code above this line
  }
  render() {
    return (
      <div>
        <form onSubmit={this.handleSubmit}>
          {/* Change code below this line */}
          <input 
          value= {this.change.input} 
          onChange ={this.handleChange} />
          {/* Change code above this line */}
          <button type='submit'>Submit!</button>
        </form>
        {/* Change code below this line */}
       <h1> {this.state.submit} </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/117.0.0.0 Safari/537.36

Challenge: React - Create a Controlled Form

Link to the challenge:

You have a couple of small errors in your code:

  1. You have typed the word change here by mistake I think: value= {this.change.input}
  2. Your h1 element will not pass the test because there are spaces before and after {this.state.submit}
1 Like

Thanks
i really appreciate

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.