Tell us what’s happening:
Hi. I have already passed the test, but a doubt remains.
I was under the impression that e.target.value referred to the value attribute of textarea. That seemed weird since originally value={this.state.userInput} and then, inside handleChange the same userInput is set to e.target.value (would that mean they are referencing each other?).
Next, I tried removing the value attribute of textarea and running the test again. Surprisingly to me, I still passed the test. I’ve searched about the value attribute and MDN says it “defines a default value which will be displayed in the element on page load”. However, it also says that “<textarea> does not support the value attribute”.
- What is the purpose of the
valueattribute intextareahere? - Is it connected to
e.target.value?
Thanks!
**Your code so far**
const textAreaStyles = {
width: 235,
margin: 5
};
class MyToDoList extends React.Component {
constructor(props) {
super(props);
this.state = {
userInput: '',
toDoList: []
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleSubmit() {
const itemsArray = this.state.userInput.split(',');
this.setState({
toDoList: itemsArray
});
}
handleChange(e) {
this.setState({
userInput: e.target.value
});
}
render() {
const items = this.state.toDoList.map(item => <li>{item}</li>)
return (
<div>
<textarea
onChange={this.handleChange}
value={this.state.userInput}
style={textAreaStyles}
placeholder='Separate Items With Commas'
/>
<br />
<button onClick={this.handleSubmit}>Create List</button>
<h1>My "To Do" List:</h1>
<ul>{items}</ul>
</div>
);
}
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 Safari/537.36.
Challenge: Use Array.map() to Dynamically Render Elements
Link to the challenge: