React - Create nested components with loops

后端 未结 14 1534
情话喂你
情话喂你 2020-12-30 01:27

I have a little issue with React. I can\'t create a nested component with a for loop. What I want to do is create 9 cells of a table and then create 3 rows with 3 cells for

14条回答
  •  礼貌的吻别
    2020-12-30 02:02

    This snippet uses map in a way similar to how we define a nested loop.

    const buildBoard = [0,1,2].map((row)=>{
          return (
            
    { [0,1,2].map((col)=>{ return ( this.renderSquare(row*3+col) ) }) }
    ) }); return (
    {buildBoard}
    );

提交回复
热议问题