Guys, I met an interesting problem in Learn React for free> Meme generator > Boxes challenge part 5 for toggle function
When I update prevState inside setState and return prevState the real state is not updated (the whole component does not rerender as well). However console.log shows the correctly updated prevState before I return prevState and when I use the function (toggle) again it takes the updated prevState and also correctly update it
The problem is gone if I return a copy of [...prevState] instead of prevState. In that case the state and component are updated correctly
Why doesn't it work in the first case?