forked from bradtraversy/react_native_shopping_list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddItem.js
55 lines (51 loc) · 1.04 KB
/
AddItem.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
import React, {useState} from 'react';
import {
View,
Text,
StyleSheet,
TextInput,
TouchableOpacity,
} from 'react-native';
import Icon from 'react-native-vector-icons/dist/FontAwesome';
const AddItem = ({addItem}) => {
const [text, setText] = useState('');
const onChange = textValue => setText(textValue);
return (
<View>
<TextInput
placeholder="Add Item..."
style={styles.input}
onChangeText={onChange}
value={text}
/>
<TouchableOpacity
style={styles.btn}
onPress={() => {
addItem(text);
setText('');
}}>
<Text style={styles.btnText}>
<Icon name="plus" size={20} /> Add Item
</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
input: {
height: 60,
padding: 8,
margin: 5,
},
btn: {
backgroundColor: '#c2bad8',
padding: 9,
margin: 5,
},
btnText: {
color: 'darkslateblue',
fontSize: 20,
textAlign: 'center',
},
});
export default AddItem;