Created
May 5, 2018 23:54
-
-
Save truthseekers/b7acef8253fba8f8f672e3ede58442bb to your computer and use it in GitHub Desktop.
react todo list 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TodoList extends React.Component{ | |
constructor(props){ | |
super(props); | |
this.state = { | |
items: ['Buy enchiladas', 'Buy Carrots', 'Buy Celery'] | |
}; | |
} | |
getListItems(){ | |
return ( | |
this.state.items.map((item) => { | |
return ( <Todo todo={item} /> ); | |
}) | |
); | |
} | |
render(){ | |
return ( | |
<div><ul>{this.getListItems()}</ul></div> | |
); | |
} | |
} | |
class Todo extends React.Component { | |
constructor(props){ | |
super(props); | |
} | |
render() { | |
return <li>{this.props.todo}</li>; | |
} | |
} | |
ReactDOM.render(<div> | |
<App /> | |
<TodoList /> | |
</div>, document.getElementById('root')); | |
registerServiceWorker(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment