Appendix
Appendix A – Skipping the dispatch
We say that not all dispatched states end up with a change. But actually, not all dispatches end up with a successful dispatch. When a mouse clicks, it goes into the dispatch
function. It has a special pathway, and when you hit that condition and find out there's no state change, it can return early without performing a dispatch:
function dispatchAction(fiber, queue, action) { ... if (NoWorkUnderFiber) { const currentState = queue.lastRenderedState const newState = typeof action === 'function' ? action(currentState) : action if (Object.is(newState, currentState)) { return } } scheduleUpdateOnFiber(fiber) }
In the preceding dispatchAction
function, a new state is computed...