React - Create a Controlled Form

With a lot of prompting from the system, reviewing of the hints, and copying of look-a-like code, I was able to get it to run. One thing I noticed is that the end of hint 2 says to “set ‘input’ to an empty string.” I explicitly added a null string, but the solution does not seem to reset the input. Please explain this to me.

  **Your code so far**
class MyForm extends React.Component {
constructor(props) {
  this.state = {
    input: '',
    submit: ''
  this.handleChange = this.handleChange.bind(this);
  this.handleSubmit = this.handleSubmit.bind(this);
handleChange(event) {
handleSubmit(event) {
  // Change code below this line
    submit: this.state.input,
    input: ''
  // Change code above this line
render() {
  return (
      <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>
      {/* Change code below this line */}
      {/* Change code above this line */}
  **Your browser information:**

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

Challenge: React - Create a Controlled Form

Link to the challenge:

because null and an empty '' are different.

O.K. so I explicitly added an empty string (not a null string), but this is exactly what the hint called for. I don’t see what the solution code does about this hint.

The hint post has been edited a few times. In the latest version, the solution code doesn’t have the input reset. It isn’t a requirement so I guess that is fine but I think the hint should be updated then. There isn’t really any reason it should mention the input reset if it isn’t a requirement and part of the solution. I removed it from the hint.

I don’t know what you mean by a null string, null is its own primitive value.

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