P粉3203612012023-08-31 18:13:17
You need a second function to pass the data: onClick={() => gameModeHandler(gameMode.title)}
.
P粉9596764102023-08-31 11:23:12
You need to use a callback function for your onClick event. and adjust your function accordingly;
onClick event
onClick={()=>gameModeHandler(gameMode.gameModeTitle)}
onClick function
const gameModeHandler = (gameModeTitle) => { console.log(gameModeTitle) }
However, if you wish to pass a single object from the loop to the called function, you can pass the gameMode object as a parameter to the gameModeHandler function;
onClick event
onClick={()=>gameModeHandler(gameMode)}
onClick function
const gameModeHandler = (gameMode) => { console.log(gameMode) }
Obviously you can then extract gameModeTitle;
from the objectconsole.log(gameMode.gameModeTitle)