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

Function rerenderReducer

dash/deps/react-dom@18.3.1.js:15904–15953  ·  view source on GitHub ↗
(reducer, initialArg, init)

Source from the content-addressed store, hash-verified

15902 }
15903
15904 function rerenderReducer(reducer, initialArg, init) {
15905 var hook = updateWorkInProgressHook();
15906 var queue = hook.queue;
15907
15908 if (queue === null) {
15909 throw new Error('Should have a queue. This is likely a bug in React. Please file an issue.');
15910 }
15911
15912 queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
15913 // work-in-progress hook.
15914
15915 var dispatch = queue.dispatch;
15916 var lastRenderPhaseUpdate = queue.pending;
15917 var newState = hook.memoizedState;
15918
15919 if (lastRenderPhaseUpdate !== null) {
15920 // The queue doesn't persist past this render pass.
15921 queue.pending = null;
15922 var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
15923 var update = firstRenderPhaseUpdate;
15924
15925 do {
15926 // Process this render phase update. We don't have to check the
15927 // priority because it will always be the same as the current
15928 // render's.
15929 var action = update.action;
15930 newState = reducer(newState, action);
15931 update = update.next;
15932 } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
15933 // different from the current state.
15934
15935
15936 if (!objectIs(newState, hook.memoizedState)) {
15937 markWorkInProgressReceivedUpdate();
15938 }
15939
15940 hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
15941 // the base state unless the queue is empty.
15942 // TODO: Not sure if this is the desired semantics, but it's what we
15943 // do for gDSFP. I can't remember why.
15944
15945 if (hook.baseQueue === null) {
15946 hook.baseState = newState;
15947 }
15948
15949 queue.lastRenderedState = newState;
15950 }
15951
15952 return [newState, dispatch];
15953 }
15954
15955 function mountMutableSource(source, getSnapshot, subscribe) {
15956 {

Callers 2

rerenderStateFunction · 0.70

Calls 2

updateWorkInProgressHookFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…