Is something like this, having two functions handling the same event but in a different way common practice?
<code>const handleClick = (e) => {
// player sets boat part by clicking on his own tile
handleClickedTile(e.target);
console.log(currentGameState)
}
const handleInGameClick = (e) => {
// player makes attack by clicking on enemies tile
console.log(currentGameState)
}
<div className="tile" id={coordinate} onClick={currentGameState === "picking boat" ? handleClick : handleInGameClick}>
<div className="tile-circle"></div>
</div>
</code>
<code>const handleClick = (e) => {
// player sets boat part by clicking on his own tile
handleClickedTile(e.target);
console.log(currentGameState)
}
const handleInGameClick = (e) => {
// player makes attack by clicking on enemies tile
console.log(currentGameState)
}
<div className="tile" id={coordinate} onClick={currentGameState === "picking boat" ? handleClick : handleInGameClick}>
<div className="tile-circle"></div>
</div>
</code>
const handleClick = (e) => {
// player sets boat part by clicking on his own tile
handleClickedTile(e.target);
console.log(currentGameState)
}
const handleInGameClick = (e) => {
// player makes attack by clicking on enemies tile
console.log(currentGameState)
}
<div className="tile" id={coordinate} onClick={currentGameState === "picking boat" ? handleClick : handleInGameClick}>
<div className="tile-circle"></div>
</div>
I am coding warship and when clicking on a tile, it depends on the gamestate wether or not the player is guessing a field of the enemy player or if the palyer is placing a boatpart at the beginning of the game