-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathApp.js
49 lines (39 loc) · 1.07 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
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Constants } from 'expo';
import Form from './components/Form';
import TodoList from './components/TodoList';
import { TodoService } from './services/TodoService';
export default class App extends React.Component {
state = {
list: []
}
async componentDidMount(){
const list = await TodoService.list();
this.setState({list});
}
add = async (text) => {
const newItem = await TodoService.create({text});
const list = [...this.state.list, newItem];
this.setState({list});
}
remove = async (item) => {
await TodoService.remove(item.id);
const list = this.state.list.filter(itemList => itemList.id !== item.id);
this.setState({list});
}
render() {
const {state} = this;
return (
<View style={styles.container}>
<Form onAdd={this.add} />
<TodoList list={state.list} onRemove={this.remove} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
paddingTop: Constants.statusBarHeight
},
});