---
title: Use Array.map() to Dynamically Render Elements
---
# Use Array.map() to Dynamically Render Elements
---
## Hints
### Hint 1
Define the two states as a JavaScript ```object```.
```
{object: state, object: state}
```
### Hint 2
You need ```.map()``` to generate a line for every object in the array.
```javascript
this.state.toDoList.map(i =>
{i}
);
```
---
## Solutions
Solution 1 (Click to Show/Hide)
Once you add the map function, you will notice that it will generate a ```
``` for every item you put in the list.
```jsx
const textAreaStyles = {
width: 235,
margin: 5
};
class MyToDoList extends React.Component {
constructor(props) {
super(props);
// change code below this line
this.state = {
userInput: '',
toDoList: []
}
// change code above this line
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(i =>