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:
parent
455cf5ee63
commit
c86cd7b6e3
@ -104,7 +104,7 @@ function TicTacToe() {
|
|||||||
const callback = () => {
|
const callback = () => {
|
||||||
playTurn(index);
|
playTurn(index);
|
||||||
};
|
};
|
||||||
return <TicTacToeCell getState={getState} callback={callback} />;
|
return <TicTacToeCell state={gridState[index]} callback={callback} />;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -112,21 +112,21 @@ function TicTacToe() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CellProps {
|
interface CellProps {
|
||||||
getState: () => number;
|
state: number;
|
||||||
callback: () => void;
|
callback: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function TicTacToeCell({ getState, callback }: CellProps) {
|
function TicTacToeCell({ state, callback }: CellProps) {
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`TicTacToeCell ${getStateClass(getState())}`}
|
className={`TicTacToeCell ${getStateClass(state)}`}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
>
|
>
|
||||||
<p>{getStateChar(getState())}</p>
|
<p>{getStateChar(state)}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user