The useState set method is not reflecting a change immediately
@lebyy▲ 0 net votes
Problem: I am trying to learn hooks and the useState method has made me confused. I am assigning an initial value to a state in the form of an array. The set method in useState is not working for me, both with and without the spread syntax. I have made an API on… Fix (from the top answer): Much like .setState() in class components created by extending React.Component or React.PureComponent , the state update using the updater provided by useState hook is also asynchronous, and will not be reflected immediately. Also, the main issue here is not just the asynchronous nature but the fact that state values…