The event handlers might not be correct since the submit button does not return anything. What is the starting point to fix this?
class DisplayMessages extends React.Component {
constructor(props) {
super(props);
this.state = {
input: '',
messages: []
}
this.handleChange = this.handleChange.bind(this);
this.submitMessage = this.submitMessage(this);
}
// Add handleChange() and submitMessage() methods here
handleChange(event) {this.setState({input: event.target.value})}
submitMessage() {
this.setState({messages: this.state.messages.concat(this.state.input)
});
}
render() {
let listItems = messsages.map(item =>
<li>{item}</li>
);
return (
<div>
<h2>Type in a new Message:</h2>
{ /* Render an input, button, and ul below this line */ }
<input type="text" onChange={this.handleChange} />
<button type="submit" value={this.submitMessage} onClick={this.submitMessage}>Add message</button>
<ul>
{listItems}
</ul>
{ /* Change code above this line */ }
</div>
);
}
};
Challege: Manage State Locally First
Learn React and Redux: Manage State Locally First | freeCodeCamp.org