state has no need to be a callback as it is re rendered on boardChange. Basically you are adding an unnecessary step

This commit is contained in:
edwardbrodski 2023-09-21 23:06:46 +01:00
parent 455cf5ee63
commit c86cd7b6e3

View File

@ -104,7 +104,7 @@ function TicTacToe() {
const callback = () => {
playTurn(index);
};
return <TicTacToeCell getState={getState} callback={callback} />;
return <TicTacToeCell state={gridState[index]} callback={callback} />;
})}
</div>
</div>
@ -112,21 +112,21 @@ function TicTacToe() {
}
interface CellProps {
getState: () => number;
state: number;
callback: () => void;
}
function TicTacToeCell({ getState, callback }: CellProps) {
function TicTacToeCell({ state, callback }: CellProps) {
function handleClick() {
callback();
}
return (
<div
className={`TicTacToeCell ${getStateClass(getState())}`}
className={`TicTacToeCell ${getStateClass(state)}`}
onClick={handleClick}
>
<p>{getStateChar(getState())}</p>
<p>{getStateChar(state)}</p>
</div>
);
}