Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimise state #29

Open
ivan-unfolds opened this issue Oct 21, 2022 · 0 comments
Open

Minimise state #29

ivan-unfolds opened this issue Oct 21, 2022 · 0 comments

Comments

@ivan-unfolds
Copy link

ivan-unfolds commented Oct 21, 2022

You don't need to put the player variable in state, as you can derive this from the count variable.

ie you could replace this useEffect

setPlayer(findTurn() === "X" ? names[0] : names[1]);

with

const player = count % 2 === 0 ? names[0] : names[1]


Stretch goal:

You could also don't need state for the count variable as you can work this out from how many squares have been filled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant