Tell us what’s happening:
I have no idea what’s wrong with this code, I’ve been trying to get it to run for about 30 minutes now and I’m failing all of the tests.
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(event) {
this.setState({
input: event.target.value
});
}
submitMessage() {
let currInput = this.state.input;
this.setState({
input: "",
messages: this.state.messages.push(currInput)
});
}
render() {
var messagesArr = this.state.messages.map(function(item) {
return <li key={item}>{item}</li>
});
return (
<div>
<h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ }
<input onChange={this.handleChange}>{this.state.input}</input>
<button onClick={this.submitMessage}>Click me!</button>
<ul>{messagesArr}</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/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/manage-state-locally-first