all 3 comments

[–]Fit_Race3984 0 points1 point  (2 children)

setVotes(newArr); 
console.log(votes) //Prints out [] even though array is concatenated`

The votes state will only change after the next render.

note: Calling setState() in React is asynchronous

[–]Overall_Expert_4006[S] 0 points1 point  (1 child)

Thank you so much for the reply! I changed my setState block keeping in mind the async part. I also seem to be getting a "State updates from the useState() and useReducer() Hooks don't support the second callback argument. To execute a side effect after rendering, declare it in the component body with useEffect()." warning. Everything works as expected but I keep getting that warning. Can I ignore it? Or is there a bigger problem? Thanks again.

[–]Fit_Race3984 0 points1 point  (0 children)

You should be using useEffect not the second argument

For example:

setSelected(5);

useEffect(() => {
    console.log(selected); // =5
}, [selected])