Aim: I want to render 64 <Square /> elements with <br/> after each 8 elements
Problem: The script outputs just one block and then stops and nothing more happens.
Source Code:
import React from 'react';
import ReactDOM from 'react-dom';
import './style.css';
class Square extends React.Component {
render() {
return <div id="block"></div>;
}
}
class Board extends React.Component {
renderSquare() {
for (let i = 1; i <= 64; i++) {
if (i % 8 == 0) {
return <br />;
} else {
return <Square />;
}
}
}
render() {
return <div>{this.renderSquare()}</div>;
}
}
function Game() {
return (
<div id="board">
<Board />
</div>
);
}
ReactDOM.render(<Game />, document.getElementById('root'));
returns a value from a function - your attempt would only output 56<Square>even if you could return like that anyway