Posted On: October 5th 2026, 02:06 am
P128: setInterval inside useEffect with empty deps runs once — its callback closes over state from that single render. State keeps updating, but the interval callback never sees anything but the value it captured at mount.
setCount(c => c + 1) reads React's current state instead of the closure. Need the latest value for more than setState? Keep a ref in sync and read ref.current.
🔖 save slide 5.
#reactnative #react #typescript #javascript #cleancode