Home / Function/ finishClassComponent() — react Function Reference

finishClassComponent() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  fec6f182_8acb_a259_b114_e6d1db8ac64b["finishClassComponent()"]
  0be70812_cc0c_b210_f84f_8e61dd5f831c["ReactFiberBeginWork.js"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|defined in| 0be70812_cc0c_b210_f84f_8e61dd5f831c
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b["updateClassComponent()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| fec6f182_8acb_a259_b114_e6d1db8ac64b
  0516fb13_8886_d15c_4bfa_1bd5d35db45d["mountIncompleteClassComponent()"]
  0516fb13_8886_d15c_4bfa_1bd5d35db45d -->|calls| fec6f182_8acb_a259_b114_e6d1db8ac64b
  add16f45_ce6d_6414_6371_4a68ab583d28["markRef()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| add16f45_ce6d_6414_6371_4a68ab583d28
  6cb202e6_76dc_0479_ff31_d0ef23610882["bailoutOnAlreadyFinishedWork()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| 6cb202e6_76dc_0479_ff31_d0ef23610882
  30a57660_53cb_2d22_5548_945a7cccdd50["setCurrentFiber()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| 30a57660_53cb_2d22_5548_945a7cccdd50
  1df0dd5b_17c8_c98c_3521_17154496ef7a["markComponentRenderStarted()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| 1df0dd5b_17c8_c98c_3521_17154496ef7a
  88d91075_df31_e6fc_5535_80030045f42a["setIsStrictModeForDevtools()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| 88d91075_df31_e6fc_5535_80030045f42a
  c88117c7_b46d_b4e4_536c_462d4e08c01e["markComponentRenderStopped()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| c88117c7_b46d_b4e4_536c_462d4e08c01e
  bef71511_dd51_a4d2_e857_595b11395fcd["forceUnmountCurrentAndReconcile()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| bef71511_dd51_a4d2_e857_595b11395fcd
  cf5641cc_b89e_d6b2_5d40_41ad5bbdd682["reconcileChildren()"]
  fec6f182_8acb_a259_b114_e6d1db8ac64b -->|calls| cf5641cc_b89e_d6b2_5d40_41ad5bbdd682
  style fec6f182_8acb_a259_b114_e6d1db8ac64b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberBeginWork.js lines 1688–1780

function finishClassComponent(
  current: Fiber | null,
  workInProgress: Fiber,
  Component: any,
  shouldUpdate: boolean,
  hasContext: boolean,
  renderLanes: Lanes,
) {
  // Refs should update even if shouldComponentUpdate returns false
  markRef(current, workInProgress);

  const didCaptureError = (workInProgress.flags & DidCapture) !== NoFlags;

  if (!shouldUpdate && !didCaptureError) {
    // Context providers should defer to sCU for rendering
    if (hasContext) {
      invalidateContextProvider(workInProgress, Component, false);
    }

    return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  }

  const instance = workInProgress.stateNode;

  // Rerender
  if (__DEV__) {
    setCurrentFiber(workInProgress);
  }
  let nextChildren;
  if (
    didCaptureError &&
    typeof Component.getDerivedStateFromError !== 'function'
  ) {
    // If we captured an error, but getDerivedStateFromError is not defined,
    // unmount all the children. componentDidCatch will schedule an update to
    // re-render a fallback. This is temporary until we migrate everyone to
    // the new API.
    // TODO: Warn in a future release.
    nextChildren = null;

    if (enableProfilerTimer) {
      stopProfilerTimerIfRunning(workInProgress);
    }
  } else {
    if (enableSchedulingProfiler) {
      markComponentRenderStarted(workInProgress);
    }
    if (__DEV__) {
      nextChildren = callRenderInDEV(instance);
      if (workInProgress.mode & StrictLegacyMode) {
        setIsStrictModeForDevtools(true);
        try {
          callRenderInDEV(instance);
        } finally {
          setIsStrictModeForDevtools(false);
        }
      }
    } else {
      nextChildren = instance.render();
    }
    if (enableSchedulingProfiler) {
      markComponentRenderStopped();
    }
  }

  // React DevTools reads this flag.
  workInProgress.flags |= PerformedWork;
  if (current !== null && didCaptureError) {
    // If we're recovering from an error, reconcile without reusing any of
    // the existing children. Conceptually, the normal children and the children
    // that are shown on error are two different sets, so we shouldn't reuse
    // normal children even if their identities match.
    forceUnmountCurrentAndReconcile(
      current,
      workInProgress,
      nextChildren,
      renderLanes,
    );
  } else {
    reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  }

Domain

Subdomains

Frequently Asked Questions

What does finishClassComponent() do?
finishClassComponent() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberBeginWork.js.
Where is finishClassComponent() defined?
finishClassComponent() is defined in packages/react-reconciler/src/ReactFiberBeginWork.js at line 1688.
What does finishClassComponent() call?
finishClassComponent() calls 8 function(s): bailoutOnAlreadyFinishedWork, forceUnmountCurrentAndReconcile, markComponentRenderStarted, markComponentRenderStopped, markRef, reconcileChildren, setCurrentFiber, setIsStrictModeForDevtools.
What calls finishClassComponent()?
finishClassComponent() is called by 2 function(s): mountIncompleteClassComponent, updateClassComponent.

Analyze Your Own Codebase

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

Try Supermodel Free