-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
51 lines (44 loc) · 1.52 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
import React, { useState } from 'react';
import { StyleSheet, View, Button, FlatList, } from 'react-native';
import GoalInput from "./components/GoalInput"
import GoalItem from "./components/GoalItem"
export default function App() {
const [enteredGoal, setEnteredGoal] = useState('')
const [courseGoals, setCourseGoals] = useState([])
const [showModal, setShowModal] = useState(false)
const goalinputHandler = (enteredText) => {
setEnteredGoal(enteredText)
}
const addGoalHandler = () => {
if (enteredGoal) {
setCourseGoals(currentGoals => [...currentGoals, { uid: Math.random().toString(), value: enteredGoal }])
console.log(courseGoals)
setEnteredGoal('')
setShowModal(modalState => !modalState)
}
}
const deleteGoalHandler = (goalId) => {
// console.log("goalid", goalId)
setCourseGoals(currentGoals => {
return currentGoals.filter(goal => goal.uid !== goalId)
})
}
return (
<View style={styles.screen}>
<Button title="Add New Goal" onPress={() => setShowModal(modalState => !modalState)} />
<GoalInput showModal={showModal} setShowModal={setShowModal} goalinputHandler={goalinputHandler} addGoalHandler={addGoalHandler} enteredGoal={enteredGoal} />
<FlatList
data={courseGoals}
keyExtractor={(item, index) => item.uid}
renderItem={itemData => (
<GoalItem itemData={itemData} onDelete={deleteGoalHandler} />
)}
/>
</View>
);
}
const styles = StyleSheet.create({
screen: {
padding: 50,
},
});