我想显示一个50x50单元格的网格.我创建了一个单元、棋盘和游戏组件.单元组件没有在电路板组件内呈现,所以我只看到一个蓝屏.我对此的react 是新的.求求你,我只是想了解和学习.谢谢

单元格组件:

export default function Cell({ value, colour, rowIndex, colIndex, clickAction }) {
      return (
        <div
          onClick={(e) => clickAction(e, rowIndex, colIndex)}
          style={{
            border: '1px solid black',
            display: 'flex',
            placeContent: 'center center',
            alignItems: 'center',
            backgroundColor: colour,
          }}
        >{value}
        </div>
      )
}

电路板组件:

import '../App.css'

export default function Board({ row, column, pix }) {
      return (
        <div style={{
          display: 'grid',
          gridTemplateColumns: `repeat(50, 25px)`,
          gridTemplateRows: `repeat(50, 25px)`,
        }}>
        </div>
      )
}

游戏组件:

import Cell from './Components/Cell'
import Board from './Components/Board'
import { useState } from 'react'
import './App.css'

export default function Game() {
      const boardDimensions = {
        width: 50,
        height: 50
      }
    
      const array2D = Array(boardDimensions.height).fill().map((row) => Array(boardDimensions.width).fill(0))
      const [fiboCells, setFiboCells] = useState(array2D)
    
      return (
        <div className="center">
          <Board row={50} column={50} pix={25}>
            {
              fiboCells.map((row, i) => row.map((col, j) => (
                <Cell
                  value={col}
                  rowIndex={i}
                  colIndex={j}
                  colour="red"
                />
              )))
            }
          </Board>
        </div>
      )
}

应用程序组件:

import './App.css';
import Game from './Game'

function App() {
      return (
        <Game/>
      );
}

export default App;

App.css:

.center {
  display: flex;
  place-content: center center;
  align-items: center;
  flex-direction: column;
  background-color: #00308F;
  height: 100vh;
  font-size: 12px;
}

我希望看到一个50x50的零格子

推荐答案

由于您将单元格作为Board组件的子级传递,因此Board组件应该如下所示

import '../App.css'

export default function Board({ row, column, pix, children }) {
      return (
        <div style={{
          display: 'grid',
          gridTemplateColumns: `repeat(50, 25px)`,
          gridTemplateRows: `repeat(50, 25px)`,
        }}>
            {children}
        </div>
      )
}

Javascript相关问答推荐

具有相同参数的JS类

使用TMS Web Core中的HTML模板中的参数调用过程

了解Node.js中的EventEums和浏览器中的addEventEums之间的关系

为什么这个JS模块在TypeScript中使用默认属性导入?""

在这种情况下,如何 for each 元素添加id?

在观察框架中搜索CSV数据

自定义高图中的x轴标签序列

当点击注册页面上的注册按钮时,邮箱重复

PDF工具包阿拉伯字体的反转数字

如何在ASP.NET中使用Google Charts API JavaScript将条形图标签显示为绝对值而不是负值

如何修复我的数据表,以使stateSave正常工作?

在浏览器中触发插入事件时检索编码值的能力

在我的index.html页面上找不到我的Java脚本条形图

使用Nuxt Apollo在Piniastore 中获取产品细节

钛中的onClick事件需要在两次点击之间等待几秒钟

按下单键和多值

与svg相反;S getPointAtLength(D)-我想要getLengthAtPoint(x,y)

如何根据查询结果重新排列日期

本地损坏的Java脚本

如何在TransformControls模式下只保留箭头进行翻译?