-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
58 lines (44 loc) · 1.14 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
50
51
52
53
54
55
56
57
58
import { StyleSheet, Text, View, FlatList } from 'react-native';
import { useState } from "react";
import Item from "./components/Item"
import AddItem from './components/AddItem';
export default function App() {
const [counter,setCounter] = useState(3)
const [items, setItems] = useState([
{id:0,title:'Oranges'},
{id:1,title:'Bananas'},
{id:2,title:'Milk'},
])
function deleteItem(id){
setItems(items.filter(item => item.id !== id))
}
function addItem(title){
const newItems = [...items, {id: counter, title:title}]
setItems(newItems)
setCounter(counter + 1)
}
return (
<View style={styles.headerText}>
<Text style={[styles.headerText, styles.fontStyle]}>Shopping list</Text>
<AddItem addItem={addItem} />
{/* flatlist mapping */}
<FlatList data={items} renderItem={({item})=> {
return (
<Item itemStyle={styles.item} data={item} deleteItem={deleteItem} />
)
}} />
</View>
);
}
const styles = StyleSheet.create({
headerText:{
textAlign:'center',
marginTop:60,
},
fontStyle:{
fontSize:30
},
item:{
fontSize:25,
}
})