React and Redux - Manage State Locally First

What’s wrong with my code? The result is exactlt the same as what expected, but it doesn’t pass. Or the section is problematic?

  **Your code so far**
class DisplayMessages extends React.Component {
constructor(props) {
  this.state = {
    input: '',
    messages: []
// Add handleChange() and submitMessage() methods here
  const {input, messages}=this.state;
  this.setState({, messages:[...messages]})
  let inputBox=document.querySelector('#input');
  const {input, messages}=this.state;
    alert('You typed in nothing!')
  } else {
    this.setState({input:'', messages:[...messages,input]});
render() {
  return (
      <h2>Type in a new Message:</h2>
      { /* Render an input, button, and ul below this line */ }
      <input id='input' type='text' onChange={this.handleChange}/>
      <button onClick={this.submitMessage}>Add message</button>
            return <li>{message}</li>
      { /* 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 and Redux - Manage State Locally First

Link to the challenge:

For an input element to be a controlled element, it should have the value property set to a state variable, in this case, this.state.input

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