Skip to content
Advertisement

I can’t add a classname in React with useEffect or?

I have a Sudoku solver project in react. And I want to style it with react or css. I tried both ways and ended up in a confusion. The grid component is my main component and I want to style the board like this:

enter image description here

And here is my simple CSS code

JavaScript

And my Grid.jsx

JavaScript

So how can I achieve the same result in the picture ?

Advertisement

Answer

I suggest you to use a more standard React approach, which is to use Composition. Basically in your Grid you have cells, which is the smallest Component, then you have 9 Squares, which are subunits of 9 cells.

This is a perfect example of composition:

JavaScript
JavaScript
JavaScript
Advertisement