React and Redux - Manage State Locally First

Tell us what’s happening:

Console:

[ReferenceError: handleChange is not defined]
Build error, open your browser console to learn more.

Your code so far

class DisplayMessages extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      input: '',
      messages: []
    };
    handleChange = handleChange.bind(this);
    submitMessage = submitMessage.bind(this);
  }
  // Add handleChange() and submitMessage() methods here
  handleChange(e) {
    this.setState({
      input: e.target.value
    })
  }
  submitMessage() {
    this.setState(currentState => ({
      input: '',
      message: [...currentState.messages, currentState.input]
    }))
  }

  render() {
    return (
      <div>
        <h2>Type in a new Message:</h2>
        { /* Render an input, button, and ul below this line */ }
        <input onChange={handleChange} />
        <button onClick={submitMessage}>Submit</button>
        <ul></ul>
        { /* Change code above this line */ }
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

React and Redux - Manage State Locally First

1 Like

You’ve just defined two (global) variables that reference non-existent functions.

handleChange and submitMessage are properties of object that DisplayMessages creates. You refer to object properties from inside the object they live in using this

2 Likes

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