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

Function dispatchSetState

dash/deps/react-dom@18.3.1.js:16651–16724  ·  view source on GitHub ↗
(fiber, queue, action)

Source from the content-addressed store, hash-verified

16649 }
16650
16651 function dispatchSetState(fiber, queue, action) {
16652 {
16653 if (typeof arguments[3] === 'function') {
16654 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().');
16655 }
16656 }
16657
16658 var lane = requestUpdateLane(fiber);
16659 var update = {
16660 lane: lane,
16661 action: action,
16662 hasEagerState: false,
16663 eagerState: null,
16664 next: null
16665 };
16666
16667 if (isRenderPhaseUpdate(fiber)) {
16668 enqueueRenderPhaseUpdate(queue, update);
16669 } else {
16670 var alternate = fiber.alternate;
16671
16672 if (fiber.lanes === NoLanes && (alternate === null || alternate.lanes === NoLanes)) {
16673 // The queue is currently empty, which means we can eagerly compute the
16674 // next state before entering the render phase. If the new state is the
16675 // same as the current state, we may be able to bail out entirely.
16676 var lastRenderedReducer = queue.lastRenderedReducer;
16677
16678 if (lastRenderedReducer !== null) {
16679 var prevDispatcher;
16680
16681 {
16682 prevDispatcher = ReactCurrentDispatcher$1.current;
16683 ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
16684 }
16685
16686 try {
16687 var currentState = queue.lastRenderedState;
16688 var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
16689 // it, on the update object. If the reducer hasn't changed by the
16690 // time we enter the render phase, then the eager state can be used
16691 // without calling the reducer again.
16692
16693 update.hasEagerState = true;
16694 update.eagerState = eagerState;
16695
16696 if (objectIs(eagerState, currentState)) {
16697 // Fast path. We can bail out without scheduling React to re-render.
16698 // It's still possible that we'll need to rebase this update later,
16699 // if the component re-renders for a different reason and by that
16700 // time the reducer has changed.
16701 // TODO: Do we still need to entangle transitions in this case?
16702 enqueueConcurrentHookUpdateAndEagerlyBailout(fiber, queue, update, lane);
16703 return;
16704 }
16705 } catch (error) {// Suppress the error. It will throw again in the render phase.
16706 } finally {
16707 {
16708 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…