I want updated playerNames, so that I can dispatch it,
const [playerNames, setPlayersName] = React.useState([])
const onCLick=(event)
{
setPlayersName(prev=>[...prev,event.target.value])
dispatch(selectPlayers(playerNames))
}
I want updated playerNames, so that I can dispatch it,
const [playerNames, setPlayersName] = React.useState([])
const onCLick=(event)
{
setPlayersName(prev=>[...prev,event.target.value])
dispatch(selectPlayers(playerNames))
}
You can use an useEffect
hook to get the updated values which works same as componentDidUpdate
useEffect(() => {
console.log(playerNames, 'Updated playerNames value')
}, [playerNames])