首页 > 解决方案 > 在组件上使用 .map 会导致组件返回“渲染中没有返回任何内容......”错误

问题描述

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null从我的反应组件中得到。它工作正常,然后我添加了一个.map复制组件并开始收到错误。我看过这个答案这个答案这个答案这个答案,但没有找到我的答案

const AdvisorData = ({weekListForAllAdvisorsOfState}) => {
    const data = usePreloadedQuery(query, queryReference);
    let {forecast} = data
    forecast.map((ind, index) => {
        return (
          <TableRow key={ind.referralCode}>
              <AdvisorTableCell>
                  <pw-subtitle size="small" color="black">{ind.referralCode}</pw-subtitle>
                  <div style={{ flexBasis: "100%" }} />
                  <pw-subtitle size="small" color="grey">{ind.postalCode}</pw-subtitle>
              </AdvisorTableCell>
          </TableRow>
        )
    })
}

标签: reactjs

解决方案


你试过这种方式吗?

const AdvisorData = ({weekListForAllAdvisorsOfState}) => {
    const data = usePreloadedQuery(query, queryReference);
    let {forecast} = data
        return (
        forecast.map((ind, index) => {
          <TableRow key={ind.referralCode}>
              <AdvisorTableCell>
                  <pw-subtitle size="small" color="black">{ind.referralCode}</pw-subtitle>
                  <div style={{ flexBasis: "100%" }} />
                  <pw-subtitle size="small" color="grey">{ind.postalCode}</pw-subtitle>
              </AdvisorTableCell>
              {weekListForAllAdvisorsOfState}
          </TableRow>
        )
    }})

推荐阅读