MCPcopy Create free account
hub / github.com/academind/react-native-practical-guide-code / App

Function App

code/02-basics/09-utilizing-props/App.js:7–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import GoalInput from './components/GoalInput';
6
7export default function App() {
8 const [courseGoals, setCourseGoals] = useState([]);
9
10 function addGoalHandler(enteredGoalText) {
11 setCourseGoals((currentCourseGoals) => [
12 ...currentCourseGoals,
13 { text: enteredGoalText, id: Math.random().toString() },
14 ]);
15 }
16
17 return (
18 <View style={styles.appContainer}>
19 <GoalInput onAddGoal={addGoalHandler} />
20 <View style={styles.goalsContainer}>
21 <FlatList
22 data={courseGoals}
23 renderItem={(itemData) => {
24 return <GoalItem text={itemData.item.text} />;
25 }}
26 keyExtractor={(item, index) => {
27 return item.id;
28 }}
29 alwaysBounceVertical={false}
30 />
31 </View>
32 </View>
33 );
34}
35
36const styles = StyleSheet.create({
37 appContainer: {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected