1export default function App() {
2 const [enteredGoal,setEnteredGoal] = useState('');
3 const [courseGoals, setCourseGoals] = useState([]);
4 const goalInputHandler = (enteredText) => {
5 setEnteredGoal(enteredText);
6 }
7 const addGoalHandler = () => {
8 setCourseGoals(currentGoals =>
9 [...currentGoals,{key:Math.random().toString(),value:enteredGoal}]
10 )
11 }
12
13 return (
14 <View style={styles.screen}>
15 <View>
16 <View style={styles.otherview}>
17 <TextInput
18 placeholder='A goal'
19 style={styles.textinput}
20 onChangeText={goalInputHandler}
21 value={enteredGoal}/>
22 <Button title='Add' onPress={addGoalHandler}/>
23 </View>
24 </View>
25
26 <FlatList
27 data={courseGoals}
28 renderItem={itemData => (
29 <View style={styles.listItem}>
30 <Text>{itemData.item.value}</Text>
31 </View>
32 )}
33 />
34
35
36
37 </View>
38 );
39}