简体   繁体   English

map function 未在反应 jsx 中呈现

[英]map function not rendering in react jsx

I am new to react and was trying to use a map function inside jsx to render an array.我是新来的反应,并试图在 jsx 中使用 map function 来呈现数组。 However nothing gets rendered inside the loop.然而,循环内没有渲染任何内容。

I am passing data to my child component like this:我将数据传递给我的子组件,如下所示:

                            {showMaterialConfirmModal && (
                            <MaterialModalConfirm
                              closeModal={setshowMaterialConfirmModal}
                              orderList={orderListE}
                              itemList={itemListE}
                              errorList={errorListE}
                              title="Success"
                            />
                          )}

and inside the child component I am calling the map function like this:在子组件内部,我像这样调用 map function:

              <Card>
              <GridContainer>
                <GridItem xs={12}>Design Successful for: 0</GridItem>
                <h5>Order:{props.orderList[0]}</h5>
                {props.orderList.map((order, i) => {
                  <div>
                    {order}
                    <h1>Hi</h1>
                    {/* <GridItem xs={12}>
                      order/item no {order[i]}/{props.itemList[i]} due to{" "}
                      {props.errorList[i]}
                    </GridItem> */}
                  </div>;
                })}
              </GridContainer>
            </Card>

The data in orderList is coming in the tag however nothing gets printed which is inside the loop. orderList 中的数据来自标签,但是在循环内没有打印任何内容。

I have checked various documents to run the map function however I am at a loss as to why nothing is getting printed.我检查了各种文件来运行 map function 但是我不知道为什么什么都没有打印出来。

Please help请帮忙

I think you are missing a return here:我认为您在这里缺少return

{props.orderList.map((order, i) => {
    return (
      <div>
        {order}
        <h1>Hi</h1>
      </div>);
  })}

or或者

{props.orderList.map((order, i) => (
      <div>
        {order}
        <h1>Hi</h1>
      </div>
  ))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM