Created
June 22, 2019 22:13
-
-
Save AlfieDarko/099ee9ae48727229d2b4c652464a4e71 to your computer and use it in GitHub Desktop.
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
import React, { Component } from 'react'; | |
import './App.css'; | |
import List from './ToDoList'; | |
export default class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
term: '', | |
items: [] | |
}; | |
} | |
onChange = (event) => { | |
this.setState({ term: event.target.value }); | |
} | |
onSubmit = (event) => { | |
event.preventDefault(); | |
this.setState({ | |
term: '', | |
items: [...this.state.items, this.state.term] | |
}); | |
} | |
deleteItem = ( event ) => { | |
event.preventDefault(); | |
const { items } = this.state; | |
const newItems = items.length > 0 ? items.slice(0, -1) : items | |
this.setState({ items: newItems}); | |
} | |
render() | |
{return ( | |
<div> | |
<h1>Task Planner</h1> | |
<form className="App" onSubmit={this.onSubmit}> | |
<input value={this.state.term} onChange={this.onChange} /> | |
<button>Submit</button> | |
<button onClick={this.deleteItem}>Delete</button> | |
</form> | |
<List items={this.state.items} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment