export default function Raffle(){
/*......*/
setCandidates(() => {
candidates.splice(winnerIdx,1) //(*)
return [...candidates];
})
}
}
at (*) line, setCandidates Function remove 2 candidates. but below is run as expected.
setCandidates(() => {
let remain = [...candidates];
remain.splice(winnerIdx,1);
return [...remain];
})
I don't know why the splice method activate twice in first case.
what happened when i modified state in setState function?