//This code working but not pass the test can you tell me where is the problem?
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(e){
this.setState(
{
input: e.target.value,
}
);
}
submitMessage(e){
e.preventDefault();
let msgInput = this.state.input
console.log(this.state.messages);
this.setState(
{
input: '',
messages: [...this.state.messages , msgInput]
}
);
}
render() {
let arrayValue = this.state.messages;
arrayValue = arrayValue.map((item) => {
return(
<li key={item}>{item}</li>
);
});
return (
<div>
<h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ }
<form onSubmit={this.submitMessage}>
<input type="text" value={this.state.input} onChange={this.handleChange} />
<input type="submit" value="Save" />
</form>
<ul>{arrayValue}</ul>
{ /* change code above this line */ }
</div>
);
}
};