-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardFunctionality.jsx
More file actions
58 lines (51 loc) · 1.36 KB
/
CardFunctionality.jsx
File metadata and controls
58 lines (51 loc) · 1.36 KB
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 React, { useState } from 'react';
import { View, Text, Button, FlatList, StyleSheet } from 'react-native';
function App() {
const [data, setData] = useState([
{id: 1, name: 'preeti', mark: 0},
{id: 2, name: 'kumudh', mark: 0},
{id: 3, name: 'karuna', mark: 0},
{id: 4, name: 'kanika', mark: 0},
])
const handleIncrease = (id) => {
setData((prev) =>
prev.map((item) =>
item.id === id ? {...item, mark: item.mark + 1} : item
)
)
}
const handleDecrease = (id) => {
setData((prev) =>
prev.map((item) =>
item.id === id ? {...item, mark: item.mark - 1} : item
)
)
}
const renderItem = ({item}) => {
return (
<View style={{width: "100%", backgroundColor: 'orange', marginVertical: 10, padding: 10,}}>
<Text>Id: {item.id}</Text>
<Text>Name: {item.name}</Text>
<Text>mark: {item.mark}</Text>
<Button title='increase' onPress={() => handleIncrease(item.id)}/>
<Button title='decrease' onPress={() => handleDecrease(item.id)}/>
</View>
)
}
return (
<View style={styles.container}>
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={renderItem}
/>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center'
}
})
export default App;