MCPcopy
hub / github.com/facebook/react / enqueueUpdate

Function enqueueUpdate

packages/react-reconciler/src/ReactFiberClassUpdateQueue.js:223–274  ·  view source on GitHub ↗
(
  fiber: Fiber,
  update: Update<State>,
  lane: Lane,
)

Source from the content-addressed store, hash-verified

221}
222
223export function enqueueUpdate<State>(
224 fiber: Fiber,
225 update: Update<State>,
226 lane: Lane,
227): FiberRoot | null {
228 const updateQueue = fiber.updateQueue;
229 if (updateQueue === null) {
230 // Only occurs if the fiber has been unmounted.
231 return null;
232 }
233
234 const sharedQueue: SharedQueue<State> = (updateQueue: any).shared;
235
236 if (__DEV__) {
237 if (
238 currentlyProcessingQueue === sharedQueue &&
239 !didWarnUpdateInsideUpdate
240 ) {
241 const componentName = getComponentNameFromFiber(fiber);
242 console.error(
243 'An update (setState, replaceState, or forceUpdate) was scheduled ' +
244 'from inside an update function. Update functions should be pure, ' +
245 'with zero side-effects. Consider using componentDidUpdate or a ' +
246 'callback.\n\nPlease update the following component: %s',
247 componentName,
248 );
249 didWarnUpdateInsideUpdate = true;
250 }
251 }
252
253 if (isUnsafeClassRenderPhaseUpdate(fiber)) {
254 // This is an unsafe render phase update. Add directly to the update
255 // queue so we can process it immediately during the current render.
256 const pending = sharedQueue.pending;
257 if (pending === null) {
258 // This is the first update. Create a circular list.
259 update.next = update;
260 } else {
261 update.next = pending.next;
262 pending.next = update;
263 }
264 sharedQueue.pending = update;
265
266 // Update the childLanes even though we're most likely already rendering
267 // this fiber. This is for backwards compatibility in the case where you
268 // update a different component during render phase than the one that is
269 // currently renderings (a pattern that is accompanied by a warning).
270 return unsafe_markUpdateLaneFromFiberToRoot(fiber, lane);
271 } else {
272 return enqueueConcurrentClassUpdate(fiber, sharedQueue, update, lane);
273 }
274}
275
276export function entangleTransitions(root: FiberRoot, fiber: Fiber, lane: Lane) {
277 const updateQueue = fiber.updateQueue;

Callers 8

captureCommitPhaseErrorFunction · 0.90
createHydrationContainerFunction · 0.90
updateContainerImplFunction · 0.90
enqueueSetStateFunction · 0.90
enqueueReplaceStateFunction · 0.90
enqueueForceUpdateFunction · 0.90

Calls 5

errorMethod · 0.65

Tested by

no test coverage detected