diff --git a/src/App.jsx b/src/App.jsx index c869b09..e837fc4 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,11 +3,23 @@ import TodoList from './TodoList.jsx' import TodoAddForm from './TodoAddForm.jsx' class TodoApp extends React.Component { + state = { + todos:[] + } + addToDo = (go) =>{ + this.setState({todos:this.state.todos.concat(go)}); + console.log(this.state); + } + deleteToDo = (away) =>{ + this.state.todos.splice(away,1); + this.setState({todos:this.state.todos}); + } render() { return (
-

Todo App

- 123 +

Todo App之我不會只能參考助教的

+ +
); } diff --git a/src/TodoAddForm.jsx b/src/TodoAddForm.jsx index fbf6003..2443ca4 100644 --- a/src/TodoAddForm.jsx +++ b/src/TodoAddForm.jsx @@ -1,15 +1,24 @@ import React from 'react' class TodoAddForm extends React.Component { - state = { - inputText: '' + constructor(props){ + super(props) + this.state = { + inputText: '' + }; + } + handleChange = (E) => { + this.setState({inputText: E.target.value}); + } + addToDo = (E) =>{ + this.props.addToDo(this.state.inputText); + this.setState({inputText:''}); } - render() { return (
- - + +
); } diff --git a/src/TodoItem.jsx b/src/TodoItem.jsx index 170af86..2784dcb 100644 --- a/src/TodoItem.jsx +++ b/src/TodoItem.jsx @@ -1,10 +1,16 @@ import React from 'react' class TodoItem extends React.Component { + constructor(props){ + super(props) + } + deleteToDo = ()=> { + this.props.deleteToDo(this.props.position); + }; render() { return (
- + {this.props.value}
); } diff --git a/src/TodoList.jsx b/src/TodoList.jsx index d588dc4..79f780c 100644 --- a/src/TodoList.jsx +++ b/src/TodoList.jsx @@ -2,10 +2,17 @@ import React from 'react' import TodoItem from './TodoItem.jsx' class TodoList extends React.Component { + constructor(props){ + super(props) + } render() { return (
- + {this.props.todos.map((todo,i)=>{ + return( + + ); + })}
); }