From 086b6f4e5c076bd795ccabf9eb2e3da0dd0982dc Mon Sep 17 00:00:00 2001 From: data Date: Thu, 20 Jun 2019 14:44:09 -0400 Subject: [PATCH] delete tasks --- src/App.js | 11 +++++++---- src/components/tasks.js | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/App.js b/src/App.js index a404a44..45d818c 100644 --- a/src/App.js +++ b/src/App.js @@ -14,6 +14,7 @@ class App extends React.Component { this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) this.addTask = this.addTask.bind(this) + this.deleteTask = this.deleteTask.bind(this) } fetchData() { @@ -33,7 +34,7 @@ class App extends React.Component { handleChange(e) { this.setState( { [e.target.name]: e.target.value }) - console.log( this.state ) + //console.log( this.state ) } handleSubmit(e) { e.preventDefault() @@ -43,8 +44,10 @@ class App extends React.Component { addTask(e) { e.preventDefault() - console.log("Added task: ", e.target.value) - this.setState( { tasks: this.state.tasks.concat(this.state.newTask) }) + this.setState( { tasks: this.state.tasks.concat(this.state.newTask), newTask: '' }) + } + deleteTask(task) { + this.setState( { tasks: this.state.tasks.filter(t => t !== task) }) } @@ -59,7 +62,7 @@ class App extends React.Component { } renderTasks(filtered) { // {...this.state} passes everything on state to the component - return + return } render() { diff --git a/src/components/tasks.js b/src/components/tasks.js index 21a2f1b..9770b7b 100644 --- a/src/components/tasks.js +++ b/src/components/tasks.js @@ -7,10 +7,12 @@ function Tasks(props) {

{`Hello, ${props.user.name}!`}

Your tasks:

-
    {filtered.map(task =>
  • {task}
  • )}
-
New: - - +
    {filtered.map(task => +
  • + {task}
  • )}
+ + +
)