-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
58 lines (50 loc) · 1.32 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from "react";
import { StyleSheet, Text, View, StatusBar } from "react-native";
import TodoInput from "./components/TodoInput";
import TodoList from "./components/TodoList";
class App extends React.Component {
state = {
todos: [{ data: "Food at 9pm", completed: false }],
todoInput: ""
};
onTodoInput = e => {
this.setState({ todoInput: e });
};
onAddTodo = () => {
const todoItem = {
data: this.state.todoInput,
completed: false
};
const todos = [...this.state.todos];
todos.push(todoItem);
this.setState({ todos, todoInput: "" });
};
onDeleteTodo = i => {
const todos = [...this.state.todos];
const newTodos = todos.filter((item, index) => index !== i);
this.setState({ todos: newTodos });
};
onCompleteTodo = i => {
const todos = [...this.state.todos];
todos[i].completed = !todos[i].completed;
this.setState({ todos });
};
render() {
return (
<View>
<StatusBar hidden />
<TodoInput
todoInput={this.state.todoInput}
onTodoInput={this.onTodoInput}
onAddTodo={this.onAddTodo}
/>
<TodoList
todos={this.state.todos}
onCompleteTodo={this.onCompleteTodo}
onDeleteTodo={this.onDeleteTodo}
/>
</View>
);
}
}
export default App;