diff --git a/src/App.js b/src/App.js index 93d4b5e..0817069 100644 --- a/src/App.js +++ b/src/App.js @@ -1,18 +1,59 @@ import React, { Component } from 'react'; import ToDoListItem from "./ToDoListItem.js" +import "./ToDoListItem.css" import './App.css'; class App extends Component { + constructor(props) { + super(props); + this.state = { items: [], title: '', description: '' }; + this.handleSubmit = this.handleSubmit.bind(this); + this.handleChange = this.handleChange.bind(this); + } + handleChange = e => { + this.setState({[e.target.name]: e.target.value}); + }; + + handleDeleteItem = index =>{ + const item = this.state.items; + item.splice(index,1); + this.setState({items : item}); + } + handleSubmit = e => { + e.preventDefault(); + const item = this.state.items; + item.push({title: this.state.title,description: this.state.description}); + this.setState({items: item,title: '',description: ''}) + }; render() { return (
+
+ + + +
- -
+ ); } } -export default App; \ No newline at end of file +export default App; diff --git a/src/ToDoListItem.js b/src/ToDoListItem.js index 5af7931..68aa0de 100644 --- a/src/ToDoListItem.js +++ b/src/ToDoListItem.js @@ -1,15 +1,18 @@ import React, { Component } from 'react'; import './ToDoListItem.css'; - +import './App.css'; class ToDoListItem extends Component { render() { - return ( -
-
-
-
- ); - } + if (this.props.list) { + return this.props.list.map((item, index) => ( +
{this.props.deleteHandler(index)}}> +
{item.title}
+
{item.description}
+
+ ) + ); + } + } } -export default ToDoListItem; \ No newline at end of file +export default ToDoListItem;