-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp2.js
88 lines (75 loc) · 1.89 KB
/
App2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button, TextInput , ScrollView,FlatList} from 'react-native';
import React, { useState } from 'react';
export default function App2() {
const [goalInput, setGoalInput] = useState('');
const [courseGoals, setCourseGoals] = useState([]);
const goalInputHandler=(text)=> {
setGoalInput(text)
}
const addValueHandler=()=>{
setCourseGoals(courseGoals => [...courseGoals,
{id : Math.random().toString(), value: goalInput}])
}
return (
<View style={styles.screen}>
<View style={styles.inputContainer}>
<TextInput
placeholder="Course Goal"
onChangeText={goalInputHandler}
style={styles.input}
value={goalInput ? goalInput : ''}
></TextInput>
<Button title="ADD" onPress={addValueHandler}></Button>
</View>
<FlatList
keyExtractor={(item, index)=>item.id }
data={courseGoals}
renderItem={itemData=>(
<View style={styles.goalListItems}>
<Text >{itemData.item.value?itemData.item.value:''}</Text>
</View>
)}
>
</FlatList>
<View></View>
</View>
);
}
const styles = StyleSheet.create({
screen: {
padding: 50
},
output: {
padding: 50
},
input: {
width: '80%',
borderColor: 'black',
borderWidth: 1,
padding: 10
},
inputContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center'
},
outputContainer: {
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'center'
},
goalListItems: {
margin: 5,
padding: 1,
borderWidth: 1,
width: '80%',
borderColor: 'black'
}
// container: {
// flex: 1,
// backgroundColor: '#fff',
// alignItems: 'center',
// justifyContent: 'center',
// },
});