Tell us what’s happening:
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){
return this.setState({input:event.target.value})
}
submitMessage(){
this.setState({messages: [this.state.input],input: ''})
}
render() {
return (
<div>
<h2>Type in a new Message:</h2>
<input onChange={this.handleChange} type="text"/>
<button onClick={this.submitMessage}>Add message</button>
<ul>
{this.state.messages.map(item =>{
return <li>item</li>
})}
</ul>
{ /* change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0
.
Challenge: Manage State Locally First
Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/react-and-redux/manage-state-locally-first