Any mistake?
class DisplayMessages extends React.Component {
constructor(props) {
super(props);
this.state = {
input: '',
messages: []
}
}
// add handleChange() and submitMessage() methods here
handleChange(event){
this.setState({
input:event.target.value,
})
}
submitMessage(){
this.setState({
messages:[...this.state.message,this.state.input]
})
}
render() {
return (
<div>
<h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ }
<input onChange={this.handleChange.bind(this)} value={this.state.input} />
<button onClick={this.submitMessage.bind(this)} >submit</button>
<ul>
{this.state.messages.map(function(obj){
return <li>{obj}</li>
})}
</ul>
{ /* change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362
.
Challenge: Manage State Locally First
Link to the challenge: