I am pretty new to react but instead of using the common js for loop I am trying to figure out how to use the .map() to achieve the same result.
import React from 'react'
import './styles/Board.css'
import Tile from './Tile'
const Board = () => {
let board = []
printBoard(board)
return (
<div className="board">
{ board }
</div>
)
}
const printBoard = (board) => {
const boardY = [1, 2, 3, 4, 5, 6, 7, 8]
const boardX = ['a','b','c','d','e','f','g','h']
for(let x = 0; x < boardX.length; x++) {
for(let y = boardY.length - 1; y >= 0; --y) {
//saves the position in each square ex: b1
const pos = boardX[x] + "" + boardY[y]
//paints the squares and the positions
board.push(<Tile key={pos} color={ (x + y) % 2 === 0 ? "dark" : "light" } pos={pos} />)
}
}
}
export default Board
Current render
