Tell us what’s happening:
Really at loss for what’s wrong here. The app is working fine (populating list with text that I input, and when I log the input from state to the console, you can see it’s there. However, this is only passing the first two tests. Any thoughts?
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.currentTarget.value
})
}
submitMessage(){
this.setState( ({ messages }) => ({messages: [...messages, this.state.input]}))
this.setState({
input: ''
})
}
render() {
return (
<div>
<h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ }
<input
type="text"
value={this.state.input}
onChange={this.handleChange}>
</input>
<button
type="button"
onClick={this.submitMessage}>
</button>
<ul>
{this.state.messages.map(item=> (
<li>
{item}
</li>
))}
</ul>
{ /* change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
.
Link to the challenge: