nope, they're both synchronous, the callback just makes it easier to set new state depending on old state
Sure? I saw in yt videos that it's async and sync
It's not actually async. React enqueues the re-rendering of that component
https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberHooks.new.js#L1749 if setState is called while rendering, the state update is delayed, otherwise it's evaluated eagerly. doesn't depend on whether you provide a callback
https://javascript.info/microtask-queue i think that he refer to this
Обсуждают сегодня