I want updated playerNames, so that I cant send it to reducer, but after setting state I am not getting the updated state, both in if and else condition
const [playerNames, setPlayersName] = React.useState([]);
let updatePlayers = playerNames.map(item=>item.id == event.target.value.id
? {...item}
:item
setPlayersName(updatePlayers)
}else{
setPlayersName(prev=>[...prev,event.target.value])
}
dispatch(selectPlayers(playerNames))