Making setState() instant

Опубликовано: 18 Март 2026
на канале: UI Engineering
7,618
421

Why setState() in React.js is not immediate? Can we make it to update the state instantly?
Deep dive into how useState() works and how we can write our own better version.

My newsletter recommendation: (not sponsored)
⚛️ This Week in React
https://thisweekinreact.com/

⏱️ Timestamps:
00:00 - StackOverflow question
00:24 - useSyncState() hook
00:48 - Disclaimer
01:03 - Why setState is not SYNC?
01:34 - Why the result of setState is not immediate?
02:47 - Role of setState()
03:25 - Batching
04:12 - Splitting setState()
04:38 - How to implement useSyncState()
05:42 - The problem with .current
07:41 - Refactoring useSyncState()
08:04 - Solving .current problem
09:04 - Discussing drawbacks

📖 Acknowledgments & Further Reading:
StackOverflow question: https://stackoverflow.com/questions/5...
React Docs: https://react.dev/learn/state-as-a-sn...