-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
49 lines (43 loc) · 1.05 KB
/
App.js
File metadata and controls
49 lines (43 loc) · 1.05 KB
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
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import AddToDo from './src/AddToDo.js';
import ToDoList from './src/ToDoList.js';
export default class App extends Component {
state = {
items: []
}
onAdded = (text) => {
this.setState({
items: [
{ text, completed: false },
...this.state.items
]
})
}
onCompleted = (index) => {
this.setState({
items: this.state.items.map((item, i) => {
if (index != i) return item;
return {
...item,
completed: !item.completed
}
})
})
}
onDeleted = (index) => {
this.setState({
items: [...this.state.items.slice(0, index), ...this.state.items.slice(index + 1)]
})
}
render() {
const { items } = this.state;
return (
<View testID="welcome">
<Text>ToDo TDD</Text>
<AddToDo onAdded={this.onAdded} ></AddToDo>
<ToDoList items={items} onCompleted={this.onCompleted} onDeleted={this.onDeleted}></ToDoList>
</View >
);
}
}