首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >render未返回任何内容。这通常意味着缺少返回语句

render未返回任何内容。这通常意味着缺少返回语句
EN

Stack Overflow用户
提问于 2021-05-03 17:14:08
回答 1查看 34关注 0票数 0

我不知道问题出在哪里。我无法解决此错误

代码语言:javascript
复制
   import { View, Text, text, TextInput, password, Image, } from 'react-native';
   import React, { useEffect, useState, Component } from 'react';
   import { FontAwesome } from '@expo/vector-icons';
   import { AntDesign } from '@expo/vector-icons';
   import { Container, Header, Content, ListItem, CheckBox, Button, Body, Grid } from 'native-base';
   import Mycard from './Mycard'
   import { getMatches } from './Api';


   export default function Home() {

     //code

     const [matches, setmatches] = useState([]);

     useEffect(() => {
         getMatches()
           .then((data) => {
             setmatches(data.matches);
             console.log(data.matches);
           })
           .catch((error) => alert("could not load data"));
       }, []

     );

     // where is the problem ?


     return (
      <View style={{ flex: 1,}}>
        <Grid Container>
          <Grid></Grid>
           <Grid>
             {
               matches.map((match)=>
               (<Mycard match="match" />)
              )
              }
           </Grid>
        </Grid>
    </View>
     )
   }

render未返回任何内容。这通常意味着缺少返回语句。这里的错误似乎是什么?

EN

回答 1

Stack Overflow用户

发布于 2021-05-03 18:45:39

React不喜欢我们在没有给组件分配键的情况下遍历组件。您可能应该向Mycard元素添加一个key属性:

代码语言:javascript
复制
<Grid>
{
  matches.map((match, index)=> (<Mycard key={index} match={match} />))
}
</Grid>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67366317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档