Home / Function/ updateClassComponent() — react Function Reference

updateClassComponent() — react Function Reference

Architecture documentation for the updateClassComponent() function in ReactFiberBeginWork.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b["updateClassComponent()"]
  0be70812_cc0c_b210_f84f_8e61dd5f831c["ReactFiberBeginWork.js"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|defined in| 0be70812_cc0c_b210_f84f_8e61dd5f831c
  53f55fda_e2b6_2801_4fbc_525f8828d23d["updateHostRoot()"]
  53f55fda_e2b6_2801_4fbc_525f8828d23d -->|calls| 9bea19b8_e307_63f1_e3b4_89c20a3fd20b
  235e1db1_02a4_912f_7d82_ea6636c850c0["beginWork()"]
  235e1db1_02a4_912f_7d82_ea6636c850c0 -->|calls| 9bea19b8_e307_63f1_e3b4_89c20a3fd20b
  e0f62937_28bc_03b3_0af1_2dbfbdc7f4ec["createClassErrorUpdate()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| e0f62937_28bc_03b3_0af1_2dbfbdc7f4ec
  e7ca53d8_6696_2eb1_6326_4df1eb1236b0["initializeClassErrorUpdate()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| e7ca53d8_6696_2eb1_6326_4df1eb1236b0
  fec6f182_8acb_a259_b114_e6d1db8ac64b["finishClassComponent()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| fec6f182_8acb_a259_b114_e6d1db8ac64b
  365b3bf6_96da_115f_49cb_3cce0265b371["resetSuspendedCurrentOnMountInLegacyMode()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| 365b3bf6_96da_115f_49cb_3cce0265b371
  0557b097_fe16_f352_4804_dd4ff4366808["constructClassInstance()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| 0557b097_fe16_f352_4804_dd4ff4366808
  3d21bb44_e12a_666f_ff91_4155c0f8d71b["mountClassInstance()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| 3d21bb44_e12a_666f_ff91_4155c0f8d71b
  40e9392c_b382_4ef8_9ede_8ac85559673c["resumeMountClassInstance()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| 40e9392c_b382_4ef8_9ede_8ac85559673c
  d93c8e6d_2cc8_2077_fe19_1d954fc83959["updateClassInstance()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| d93c8e6d_2cc8_2077_fe19_1d954fc83959
  style 9bea19b8_e307_63f1_e3b4_89c20a3fd20b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberBeginWork.js lines 1576–1686

function updateClassComponent(
  current: Fiber | null,
  workInProgress: Fiber,
  Component: any,
  nextProps: any,
  renderLanes: Lanes,
) {
  if (__DEV__) {
    // This is used by DevTools to force a boundary to error.
    switch (shouldError(workInProgress)) {
      case false: {
        const instance = workInProgress.stateNode;
        const ctor = workInProgress.type;
        // TODO This way of resetting the error boundary state is a hack.
        // Is there a better way to do this?
        const tempInstance = new ctor(
          workInProgress.memoizedProps,
          instance.context,
        );
        const state = tempInstance.state;
        instance.updater.enqueueSetState(instance, state, null);
        break;
      }
      case true: {
        workInProgress.flags |= DidCapture;
        workInProgress.flags |= ShouldCapture;
        // eslint-disable-next-line react-internal/prod-error-codes
        const error = new Error('Simulated error coming from DevTools');
        const lane = pickArbitraryLane(renderLanes);
        workInProgress.lanes = mergeLanes(workInProgress.lanes, lane);
        // Schedule the error boundary to re-render using updated state
        const root: FiberRoot | null = getWorkInProgressRoot();
        if (root === null) {
          throw new Error(
            'Expected a work-in-progress root. This is a bug in React. Please file an issue.',
          );
        }
        const update = createClassErrorUpdate(lane);
        initializeClassErrorUpdate(
          update,
          root,
          workInProgress,
          createCapturedValueAtFiber(error, workInProgress),
        );
        enqueueCapturedUpdate(workInProgress, update);
        break;
      }
    }
  }

  // Push context providers early to prevent context stack mismatches.
  // During mounting we don't know the child context yet as the instance doesn't exist.
  // We will invalidate the child context in finishClassComponent() right after rendering.
  let hasContext;
  if (isLegacyContextProvider(Component)) {
    hasContext = true;
    pushLegacyContextProvider(workInProgress);
  } else {
    hasContext = false;
  }
  prepareToReadContext(workInProgress, renderLanes);

  const instance = workInProgress.stateNode;
  let shouldUpdate;
  if (instance === null) {
    resetSuspendedCurrentOnMountInLegacyMode(current, workInProgress);

    // In the initial pass we might need to construct the instance.
    constructClassInstance(workInProgress, Component, nextProps);
    mountClassInstance(workInProgress, Component, nextProps, renderLanes);
    shouldUpdate = true;
  } else if (current === null) {
    // In a resume, we'll already have an instance we can reuse.
    shouldUpdate = resumeMountClassInstance(
      workInProgress,
      Component,
      nextProps,
      renderLanes,
    );
  } else {
    shouldUpdate = updateClassInstance(

Domain

Subdomains

Frequently Asked Questions

What does updateClassComponent() do?
updateClassComponent() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberBeginWork.js.
Where is updateClassComponent() defined?
updateClassComponent() is defined in packages/react-reconciler/src/ReactFiberBeginWork.js at line 1576.
What does updateClassComponent() call?
updateClassComponent() calls 8 function(s): constructClassInstance, createClassErrorUpdate, finishClassComponent, initializeClassErrorUpdate, mountClassInstance, resetSuspendedCurrentOnMountInLegacyMode, resumeMountClassInstance, updateClassInstance.
What calls updateClassComponent()?
updateClassComponent() is called by 2 function(s): beginWork, updateHostRoot.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free