Tell us what’s happening:
The code below functions entirely but isn’t passing the checks. Returns the error: Cannot read property ‘target’ of undefined
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() {
this.setState({
input: event.target.value
});
}
submitMessage() {
this.setState({
messages: this.state.messages.concat(this.state.input),
input: ''
});
}
render() {
const allMessages = this.state.messages.map(function(element) {
return (<li key={element}>{element}</li>)
});
return (
<div>
<h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ }
<input value={this.state.input} onChange={this.handleChange}/>
<button onClick={this.submitMessage}>Add message</button>
<ul>
{allMessages}
</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/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/manage-state-locally-first