-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
72 lines (65 loc) · 1.8 KB
/
App.js
File metadata and controls
72 lines (65 loc) · 1.8 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, {useRef, useState} from 'react';
import {StyleSheet, View, FlatList, Button} from 'react-native';
import GoalInput from './components/GoalInput';
import GoalItem from './components/GoalItem';
const App = () => {
const [goals, setGoals] = useState([]);
const [isModalVisible, setIsModalVisible] = useState(false);
const ref = useRef(null);
const addGoalHandler = (goalTitle) => {
// setGoals([enteredGoal, ...goals]);
if (!goalTitle) {
return;
}
setGoals((currentGoals) => [
{id: Math.random().toString(), value: goalTitle},
...currentGoals,
]);
// setEnteredGoal('');
ref.current.reset();
setIsModalVisible(false);
};
const removeGoalHandler = (id) => {
setGoals((currentGoals) => currentGoals.filter((item) => item.id !== id));
};
return (
<View style={styles.screen}>
<Button title="Add New GOAL" onPress={() => setIsModalVisible(true)} />
<GoalInput
ref={ref}
isVisible={isModalVisible}
onAddGoal={addGoalHandler}
onCancel={() => setIsModalVisible(false)}
goals={goals}
/>
{/* <ScrollView style={styles.sectionBody}>
{goals.map((goal, index) => {
return (
<View style={styles.listItem}>
<Text key={index}>{goal}</Text>
</View>
);
})}
</ScrollView> */}
<FlatList
data={goals}
style={styles.sectionBody}
keyExtractor={(item) => item.id.toString()}
renderItem={(itemData) => {
return <GoalItem item={itemData.item} onDelete={removeGoalHandler} />;
}}
/>
</View>
);
};
const styles = StyleSheet.create({
screen: {
flex: 1,
padding: 40,
},
sectionBody: {
// width: '80%',
marginTop: 10,
},
});
export default App;