【问题标题】:Objects are not valid as a React child. If you meant to render a collection of children, use an array instead - FlatList对象作为 React 子级无效。如果您打算渲染一组孩子,请改用数组 - FlatList
【发布时间】:2021-12-05 15:34:22
【问题描述】:

React-native Expo CLI ,FlatList 我正在尝试使用 FlatList。但它向我显示错误-

  • 错误: 对象作为 React 子对象无效(发现:对象带有键 {seconds, nanoseconds})。如果您打算渲染一组子项,请改用数组。

faltList 代码

{
 (PostLoaded)?<FlatList
  data = {PostData}
  keyExtractor = {item => item.key}
  renderItem={(itemData) => {
    const PostInfo = itemData.item;
    // console.log(PostInfo.Name);
    return(
      <View style={style.petshowContainer}>
        <Image source={{uri:PostInfo.Image}}
          style={{width:150,height:175,borderTopLeftRadius:10,borderBottomLeftRadius:10,}}
          resizeMode='cover'
        />
       <View style={{margin:10}}>
       <Text style={{fontSize:25}}>{PostInfo.Name}</Text>
       <View style={{flexDirection:'row',alignItems:'center'}}>
       <Text style={{fontSize:15,marginRight:20}}>{PostInfo.Age}/ {PostInfo.Breed}</Text>
       <Button mode='outlined' style={{borderColor:'blue'}}>{PostInfo.Gender}</Button>
    </View>
   <Text style={{marginBottom:5}}>Available for : </Text>
   <Text>{PostInfo.From_Date} - 11/10/2021</Text>
   <Button mode="contained" style={{marginTop:10}}>PetME</Button>
     </View>
    </View>
    )
}}
  style={{backgroundColor:'red'}}
  />:<Text>loading...</Text>
}

Post Data 是一个数组,包含从 firebase 接收的对象

PostData = [{name:"narendra",Age:5.......},{.....}]

【问题讨论】:

    标签: javascript react-native expo react-native-flatlist


    【解决方案1】:

    这是由于日期格式错误造成的

    <Text>{PostInfo.From_Date} - 11/10/2021</Text>
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2020-12-22
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    相关资源
    最近更新 更多