-
Notifications
You must be signed in to change notification settings - Fork 45
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
Completo juego TicTacToe #26
base: master
Are you sure you want to change the base?
Conversation
src/components/pages/TicTacToe.js
Outdated
const gameEnded = false; | ||
const [tiles,setTiles] = React.useState(['','','','','','','','','']); | ||
const [currentPlayer,setCurrentPlayer]= React.useState(initialPlayer); | ||
const [winner,setWinner] = React.useState(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en general, está bueno tratar de tener la menor cantidad de states posible. como el winner
se puede sacar a partir del estado actual de los tiles, no es necesario que sea un state aparte. Si reemplazás esta línea por const winner = getWinner(tiles)
, debería andar igual y te ahorrás tener que setear el winner en setTileTo
y restart
src/components/pages/TicTacToe.js
Outdated
<div className='tictactoe-row'> | ||
<div className='square' value={tiles[0]} onClick={()=>{setTileTo(0, currentPlayer)}}>{tiles[0]}</div> | ||
<div className='square' value={tiles[1]} onClick={()=>{setTileTo(1, currentPlayer)}}>{tiles[1]}</div> | ||
<div className='square' value={tiles[2]} onClick={()=>{setTileTo(2, currentPlayer)}}>{tiles[2]}</div> | ||
</div> | ||
<div className='tictactoe-row'> | ||
<div className='square' value={tiles[3]} onClick={()=>{setTileTo(3, currentPlayer)}}>{tiles[3]} | ||
</div> | ||
<div className='square' value={tiles[4]} onClick={()=>{setTileTo(4, currentPlayer)}}>{tiles[4]} | ||
</div> | ||
<div className='square' value={tiles[5]} onClick={()=>{setTileTo(5, currentPlayer)}}>{tiles[5]} | ||
</div> | ||
</div> | ||
<div className='tictactoe-row'> | ||
<div className='square' value={tiles[6]} onClick={()=>{setTileTo(6, currentPlayer)}}>{tiles[6]}</div> | ||
<div className='square' value={tiles[7]} onClick={()=>{setTileTo(7, currentPlayer)}}>{tiles[7]}</div> | ||
<div className='square' value={tiles[8]} onClick={()=>{setTileTo(8, currentPlayer)}}>{tiles[8]}</div> | ||
</div> </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
acá se repite bastante código, se te ocurre como hacerlo más simple? capaz con un par de .map()
s?
No description provided.