Skip to content

Instantly share code, notes, and snippets.

@truthseekers
Created May 5, 2018 23:54
Show Gist options
  • Save truthseekers/b7acef8253fba8f8f672e3ede58442bb to your computer and use it in GitHub Desktop.
Save truthseekers/b7acef8253fba8f8f672e3ede58442bb to your computer and use it in GitHub Desktop.
react todo list 2
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