Create a Controlled Form help!

Tell us what’s happening:
PLease tell me what is the problem and it’s solution

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
this.setState({
submit: event.preventDefault()
});
}
    // c;hange code above this line
  
  render() {
    return (
      <div>
        <form onSubmit={this.handleSubmit}>
          { /* change code below this line */ }
          <input 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.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/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/create-a-controlled-form

event.preventDefault() is a method often used in plain js too ^^ It’s used to prevent the default behaviour of something ( as the name suggests ^^)

this.setState is strictly related to the react component - it’s used to change the state of the component, and in this specific case

should […] sets the component state property submit to the current input value

The event.preventDefault should be used before to change the state in your handleSubmit^^

Good luck!

Sorry but I can’t understand what to do

Sorry I didn’t get that. Can you please explain it in a better manner

As the randelldawson says.

You must call the eventDefault() in the handleSubmit(event) function.

Look into my code :

 handleSubmit(event) {
    // change code below this line
        event.preventDefault()
         this.setState({
        submit:this.state.input     
      })

You must call the eventDefault() in the handleSubmit(event) function.