第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 react-native 中找不到變量 itemData

在 react-native 中找不到變量 itemData

九州編程 2022-01-20 20:46:47
代碼 :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)行良好..
查看完整描述

2 回答

?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

它應(yīng)該是


<FlatList keyExtractor={(item, index) => item.id} 

          data={courseGoals}

          renderItem={(itemData) => <GoalItem title={itemData.item.value} }/>

或者


<FlatList keyExtractor={(item, index) => item.id} 

          data={courseGoals}

          renderItem={({item}) => <GoalItem title={item.value} }/>


查看完整回答
反對(duì) 回復(fù) 2022-01-20
?
皈依舞

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊

它應(yīng)該是這樣的:


<FlatList 

       data={courseGoals}

       renderItem={itemData => (

         

        <View  style={styles.listItem}>

          <Text>{itemData.item}</Text>

          </View>  

          )}

          />


查看完整回答
反對(duì) 回復(fù) 2022-01-20
  • 2 回答
  • 0 關(guān)注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)