MCPcopy Create free account
hub / github.com/plotly/dash / dispatchSetState

Function dispatchSetState

dash/deps/react-dom@18.2.0.js:17470–17543  ·  view source on GitHub ↗
(fiber, queue, action)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 10

errorFunction · 0.70
requestUpdateLaneFunction · 0.70
isRenderPhaseUpdateFunction · 0.70
enqueueRenderPhaseUpdateFunction · 0.70
requestEventTimeFunction · 0.70
scheduleUpdateOnFiberFunction · 0.70
entangleTransitionUpdateFunction · 0.70
markUpdateInDevToolsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…