-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathApp.js
More file actions
42 lines (35 loc) · 896 Bytes
/
App.js
File metadata and controls
42 lines (35 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {useState, useEffect} from 'react'
import './App.css';
function App() {
const[data, setData] = useState([])
const boardSize = 10;
useEffect(() => {
let newCells = [];
for (let row = boardSize - 1; row >= 0; row--) {
let rowCells = [];
for (let col = 0; col < boardSize; col++) {
const cellNumber = row * boardSize + col + 1;
rowCells.push(cellNumber);
}
if (row % 2 !== 0) {
rowCells.reverse();
}
newCells = newCells.concat(rowCells);
}
setData(newCells);
}, []);
console.log(data)
return (
<div className="App">
<div className = 'game-board'
style={{gridTemplateColumns: `repeat(${boardSize}, 1fr)`}}>
{data.map((item) => {
return(
<div className='game-cell'>{item}</div>
)
})}
</div>
</div>
);
}
export default App;