diff --git a/src/App.jsx b/src/App.jsx
index c869b09..6281a46 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,15 +1,42 @@
import React from 'react'
import TodoList from './TodoList.jsx'
import TodoAddForm from './TodoAddForm.jsx'
+// import List from './List.jsx'
class TodoApp extends React.Component {
+ constructor(props) {
+ super(props)
+ this.state = {
+ todos: []
+ }
+ }
+
+ addTodo(todo) {
+ let update_todos = this.state.todos.slice(0)
+ update_todos.push(todo)
+ // console.log('update_todos', update_todos)
+ this.setState({
+ todos: update_todos
+ })
+ }
+
+ deleteTodo(idx) {
+ let update_todos = this.state.todos.slice(0)
+ update_todos.splice(idx, 1)
+ this.setState({
+ todos: update_todos
+ })
+ }
+
render() {
return (
Todo App
- 123
+
+
- );
+ )
+
}
}
diff --git a/src/List.jsx b/src/List.jsx
new file mode 100644
index 0000000..541cc1a
--- /dev/null
+++ b/src/List.jsx
@@ -0,0 +1,30 @@
+import React from 'react'
+
+class List extends React.Component {
+ constructor(props) {
+ super(props)
+ this.state = {
+ input_text: '',
+ }
+
+ }
+
+ onTextChange(evt) {
+ this.setState({
+ input_text: evt.target.value
+ })
+ }
+
+ render() {
+ const items = ['a', 'b', 'c', 'd', 'e']
+ return (
+
+ this.onTextChange(evt)}/>
+
+ )
+ }
+}
+
+export default List
\ No newline at end of file
diff --git a/src/TodoAddForm.jsx b/src/TodoAddForm.jsx
index fbf6003..33bf743 100644
--- a/src/TodoAddForm.jsx
+++ b/src/TodoAddForm.jsx
@@ -1,15 +1,32 @@
import React from 'react'
class TodoAddForm extends React.Component {
- state = {
- inputText: ''
+ constructor(props) {
+ super(props)
+ this.state = {
+ inputText: ''
+ }
}
+
+ onTextChange(evt) {
+ this.setState({
+ inputText: evt.target.value
+ })
+ }
+
+ addText(evt) {
+ if (this.state.inputText !== ''){
+ const { addTodo } = this.props
+ addTodo(this.state.inputText)
+ }
+ }
+
render() {
return (
-
-
+ this.onTextChange(evt)}/>
+
);
}
diff --git a/src/TodoItem.jsx b/src/TodoItem.jsx
index 170af86..307b730 100644
--- a/src/TodoItem.jsx
+++ b/src/TodoItem.jsx
@@ -1,10 +1,25 @@
import React from 'react'
class TodoItem extends React.Component {
+ constructor(props) {
+ super(props)
+ }
+
render() {
+ // const {todos, deleteTodo} = this.props
+ const todos = this.props.todos
+ const deleteTodo = this.props.deleteTodo
return (
-
+ {
+ todos.map((item, idx) => {
+ return (
+
+
{item}
+
+ )
+ })
+ }
);
}
diff --git a/src/TodoList.jsx b/src/TodoList.jsx
index d588dc4..a5e3688 100644
--- a/src/TodoList.jsx
+++ b/src/TodoList.jsx
@@ -2,10 +2,16 @@ import React from 'react'
import TodoItem from './TodoItem.jsx'
class TodoList extends React.Component {
+ constructor(props) {
+ super(props)
+ }
+
render() {
+ // const todos = this.props.todos
+ const {todos, deleteTodo} = this.props
return (
-
+
);
}