首页 > 解决方案 > React 不渲染道具,但可以在 console.log 中看到

问题描述

在我的渲染中,我有这个const arr = []

在我回来时,我有这个

{
    this.state.rows.map((qc) =>
        qc.BinsByDayByOrchardsQCs.map((qc2) =>
            qc2.BinsByDayByOrchardsQCsDefects.map((qc3) =>
              {!arr.includes(qc3.Defect) && arr.push(qc3.Defect) &&
                (<div className="row table">
                    <div className="column-label bold">{qc3.Defect}</div>
                    {console.log("testing", qc3.Defect)}
                </div>)
              }
            ) 
        )
    )
}

在我的 console.log 中,我实际上可以看到 4 个结果,这是我想要的结果。它看起来像这样:

testing Scuff
testing Sunburn
testing Bruise
testing Hail damage

关于为什么页面上什么都没有呈现的任何想法?

标签: javascriptarraysreactjsobjectecmascript-6

解决方案


因为您有花括号{},您需要将它们更改为括号()或使用显式return语句:

qc2.BinsByDayByOrchardsQCsDefects.map((qc3) =>
    {!arr.includes(qc3.Defect) && arr.push(qc3.Defect) &&
        (<div className="row table">
            <div className="column-label bold">{qc3.Defect}</div>
            {console.log("testing", qc3.Defect)}
        </div>)
      )
    ) 

推荐阅读