Tell us what’s happening:
Can you help me why I can’t pass this test?
“Failed: Clicking the Add message button should call the method submitMessage which should add the current input to the messages array in state.”
Your code so far
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() {
const itemsArray = this.state.input.split(" ")
this.setState(({
messages: itemsArray,
input: ''
}))
}
render() {
const ulLi = this.state.messages.map((liItem) => <li key={liItem}>{liItem}</li>);
return (
<div>
<h2>Type in a new Message:</h2>
{ /* Render an input, button, and ul below this line */ }
<input value={this.state.input} onChange={this.handleChange}></input>
<button onClick={this.submitMessage}>Add message</button>
<ul>
{ulLi}
</ul>
{ /* Change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Challenge Information:
React and Redux - Manage State Locally First