(fiber, queue, action)
| 17468 | } |
| 17469 | |
| 17470 | function dispatchSetState(fiber, queue, action) { |
| 17471 | { |
| 17472 | if (typeof arguments[3] === 'function') { |
| 17473 | error("State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().'); |
| 17474 | } |
| 17475 | } |
| 17476 | |
| 17477 | var lane = requestUpdateLane(fiber); |
| 17478 | var update = { |
| 17479 | lane: lane, |
| 17480 | action: action, |
| 17481 | hasEagerState: false, |
| 17482 | eagerState: null, |
| 17483 | next: null |
| 17484 | }; |
| 17485 | |
| 17486 | if (isRenderPhaseUpdate(fiber)) { |
| 17487 | enqueueRenderPhaseUpdate(queue, update); |
| 17488 | } else { |
| 17489 | var alternate = fiber.alternate; |
| 17490 | |
| 17491 | if (fiber.lanes === NoLanes && (alternate === null || alternate.lanes === NoLanes)) { |
| 17492 | // The queue is currently empty, which means we can eagerly compute the |
| 17493 | // next state before entering the render phase. If the new state is the |
| 17494 | // same as the current state, we may be able to bail out entirely. |
| 17495 | var lastRenderedReducer = queue.lastRenderedReducer; |
| 17496 | |
| 17497 | if (lastRenderedReducer !== null) { |
| 17498 | var prevDispatcher; |
| 17499 | |
| 17500 | { |
| 17501 | prevDispatcher = ReactCurrentDispatcher$1.current; |
| 17502 | ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV; |
| 17503 | } |
| 17504 | |
| 17505 | try { |
| 17506 | var currentState = queue.lastRenderedState; |
| 17507 | var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute |
| 17508 | // it, on the update object. If the reducer hasn't changed by the |
| 17509 | // time we enter the render phase, then the eager state can be used |
| 17510 | // without calling the reducer again. |
| 17511 | |
| 17512 | update.hasEagerState = true; |
| 17513 | update.eagerState = eagerState; |
| 17514 | |
| 17515 | if (objectIs(eagerState, currentState)) { |
| 17516 | // Fast path. We can bail out without scheduling React to re-render. |
| 17517 | // It's still possible that we'll need to rebase this update later, |
| 17518 | // if the component re-renders for a different reason and by that |
| 17519 | // time the reducer has changed. |
| 17520 | // TODO: Do we still need to entangle transitions in this case? |
| 17521 | enqueueConcurrentHookUpdateAndEagerlyBailout(fiber, queue, update, lane); |
| 17522 | return; |
| 17523 | } |
| 17524 | } catch (error) {// Suppress the error. It will throw again in the render phase. |
| 17525 | } finally { |
| 17526 | { |
| 17527 | ReactCurrentDispatcher$1.current = prevDispatcher; |
nothing calls this directly
no test coverage detected
searching dependent graphs…