Tell us what’s happening:
Hello, I don’t fully understand what is happening with “value={this.state.input}”.
The code is working fine but If you someone could please explain what this code is doing exactly that would be helpful. Is it being passed as the prop to “event.target.value”?
Thanks for the help!
-Travis
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() {
this.setState({
messages: this.state.messages.concat(this.state.input),
input: ''
})
}
render() {
const list = this.state.messages.map((m) => <li>{m}</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}></input>
<button onClick={this.submitMessage}>Submit</button>
<ul>{list}</ul>
{ /* change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 OPR/56.0.3051.36
.
Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/manage-state-locally-first