Problems passing "Manage State Locally First"

Tell us what’s happening:
I’ve seen a few posts about this challenge, but none with the exact problem I’m having.

The code seems to work fine - the input updates the state and the messages are posted on submit. But only the first test passes, all the others do not.

The console has 4 copies of this error message:

Method “simulate” is only meant to be run on a single node. 2 found instead.

Any help is much appreciated.

Your code so far


class DisplayMessages extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      input: '',
      messages: []
    }
    this.handleChange = this.handleChange.bind(this);
    this.submitMessage = this.submitMessage.bind(this);
  }
  // add handleChange() and submitMessage() methods here
  handleChange(event) {
    this.setState({input: event.target.value});
  }
  submitMessage() {
    this.setState({input: "", messages: this.state.messages.concat([this.state.input])})
  }
  render() {
    return (
      <div>
        <h2>Type in a new Message:</h2>
        { /* render an input, button, and ul here */ }
        <input value={this.state.input} onChange={this.handleChange}/>
        <input type="button" onClick={this.submitMessage} value="submit"/>
        <ul>{this.state.messages.map((item, index) => {
          return <li key={index}>{item}</li>
        })}</ul>
        { /* change code above this line */ }
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0.

Link to the challenge:

The challenge requires you to have a ‘button’ element. Since you have used
<input type="button">, the tests are not able to find the button element. Change it to:
<button onClick={this.submitMessage}>Submit</button>
and it should work.

1 Like

Ah, thank you @Ah46. That solved it