Tell us what’s happening:
My code for this challenge seems to work as far as I can tell according to the description, but I am failing most 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() {
const inputBox = document.getElementById("inputBox");
this.setState((prevState) => ({
input: inputBox.value,
messages: prevState.messages
}));
}
submitMessage() {
this.setState(prevState => ({
input: '',
messages: [...prevState.messages.concat(prevState.input)]
}));
}
render() {
return (
<div>
<div>{this.state.input}</div>
<h2>Type in a new Message:</h2>
{ /* Render an input, button, and ul below this line */ }
<input id="inputBox" onChange={this.handleChange}/>
<button onClick={this.submitMessage}>Click Me</button>
<ul>
{
this.state.messages.map((elem, index) => <li key={index}>{elem}</li>)
}
</ul>
{ /* Change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0
Challenge Information:
React and Redux - Manage State Locally First