Hacker News new | ask | show | jobs
by imtringued 1699 days ago
setLoading just pushes an element into a queue. Calling useState will create the queue and fill it with true as initial state during the first call and then run a reducer on the entire queue to calculate the latest state. Simply calling setLoading does not modify loading. When you push an update to a queue react will rerender the component and thereby call useState again which runs the reducer which returns the latest state.

https://news.ycombinator.com/item?id=28972892