React - Create a Controlled Form

Tell us what’s happening:
The code works and passes, and even looks like the provided solution under Get Help, but I’m guess I’m wondering why I’m still getting this error in the message console:

Uncaught TypeError: Cannot read properties of null (reading ‘match’)

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.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/115.0.0.0 Safari/537.36

Challenge: React - Create a Controlled Form

Link to the challenge:

1 Like

Hi @olsen.jcm

Welcome to FCC. I’m not exactly sure whether this is related to your solution or a problem with the challenge. It looks like the tests expect an action attribute on the form element.

<form onSubmit={this.handleSubmit} action="">
  ...
</form>

The error seems to disappear, at least that is the case on my end.

2 Likes

It disappeared for me as well, thanks!!

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