在 react-native 中找不到變量 itemData
代碼 :import React, { useState } from 'react';import { StyleSheet, Text, View, Button, TextInput, ScrollView, FlatList } from 'react-native';import GoalItem from './components/GoalItem';export default function App() { const [enteredGoal, setEnteredGoal] = useState(''); const [courseGoals, setCourseGoals] = useState([]); const goalInputHandler = (enteredText) => { setEnteredGoal(enteredText); }; const addGoalHandler = () => { //console.log(enteredGoal); setCourseGoals(currentGoals => [...currentGoals, { id: Math.random().toString(), value: enteredGoal }]); }; return ( <View style={styles.screen}> <View style={styles.inputContainer}> <TextInput placeholder="Course Goal" style={styles.input} onChangeText={goalInputHandler} value={enteredGoal} /> <Button title="Add" onPress={addGoalHandler} /> </View> <FlatList keyExtractor={(item, index) => item.id} data={courseGoals} renderItem={itemData => <GoalItem title={itemData.item.value} />} /> </View> );}const styles = StyleSheet.create({ screen: { padding: 50 }, inputContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }, input: { width: '70%', borderBottomColor: 'black', borderWidth: 1, padding: 10 },});目標(biāo)項(xiàng)組件:import React from 'react';import { View, Text, StyleSheet } from 'react-native';const GoalItem = props => { return ( <View style={styles.listItem}> <Text>{props.title}</Text> </View> );};const styles = StyleSheet.create({ listItem: { padding: 10, backgroundColor: '#ccc', borderColor: 'black', borderWidth: 1, marginVertical: 10 }});export default GoalItem;錯(cuò)誤:下面是代碼,請(qǐng)檢查 Can't find variable itemData in react-native請(qǐng)問我是 react-native 的新手,我剛接觸了大約兩個(gè)小時(shí)。任何幫助,將不勝感激。提前致謝。查看代碼并分享一些建議,以便代碼運(yùn)行良好..
查看完整描述