-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
49 lines (40 loc) · 965 Bytes
/
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, { Component } from 'react'
import { View } from 'react-native'
import List from './components/List'
import Input from './components/Input'
import Title from './components/Title'
export default class App extends Component {
state = {
todos: ['Click to remove', 'Learn React Native', 'Write Code', 'App'],
}
onAddTodo = (text) => {
const {todos} = this.state
this.setState({
todos: [text, ...todos],
})
}
onRemoveTodo = (index) => {
const {todos} = this.state
this.setState({
todos: todos.filter((todo, i) => i !== index),
})
}
render() {
const {todos} = this.state
return (
<View>
<Title>
To-Do List
</Title>
<Input
placeholder={'Type a todo, then hit enter!'}
onSubmitEditing={this.onAddTodo}
/>
<List
list={todos}
onPressItem={this.onRemoveTodo}
/>
</View>
)
}
}