Home / Function/ updateClassInstance() — react Function Reference

updateClassInstance() — react Function Reference

Architecture documentation for the updateClassInstance() function in ReactFiberClassComponent.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  d93c8e6d_2cc8_2077_fe19_1d954fc83959["updateClassInstance()"]
  3805476a_1924_0e35_fff7_6afad197a523["ReactFiberClassComponent.js"]
  d93c8e6d_2cc8_2077_fe19_1d954fc83959 -->|defined in| 3805476a_1924_0e35_fff7_6afad197a523
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b["updateClassComponent()"]
  9bea19b8_e307_63f1_e3b4_89c20a3fd20b -->|calls| d93c8e6d_2cc8_2077_fe19_1d954fc83959
  7f5a1eb6_175b_de57_e39a_6c9d67383c84["resolveClassComponentProps()"]
  d93c8e6d_2cc8_2077_fe19_1d954fc83959 -->|calls| 7f5a1eb6_175b_de57_e39a_6c9d67383c84
  d83968be_2eaf_cd1b_857b_b74b96d7a349["callComponentWillReceiveProps()"]
  d93c8e6d_2cc8_2077_fe19_1d954fc83959 -->|calls| d83968be_2eaf_cd1b_857b_b74b96d7a349
  9f4500d1_a30b_b3dc_2405_2ab2117c51e4["applyDerivedStateFromProps()"]
  d93c8e6d_2cc8_2077_fe19_1d954fc83959 -->|calls| 9f4500d1_a30b_b3dc_2405_2ab2117c51e4
  2b0ae04e_0543_188d_43fc_818335c01e4c["checkShouldComponentUpdate()"]
  d93c8e6d_2cc8_2077_fe19_1d954fc83959 -->|calls| 2b0ae04e_0543_188d_43fc_818335c01e4c
  style d93c8e6d_2cc8_2077_fe19_1d954fc83959 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberClassComponent.js lines 1004–1182

function updateClassInstance(
  current: Fiber,
  workInProgress: Fiber,
  ctor: any,
  newProps: any,
  renderLanes: Lanes,
): boolean {
  const instance = workInProgress.stateNode;

  cloneUpdateQueue(current, workInProgress);

  const unresolvedOldProps = workInProgress.memoizedProps;
  const oldProps = resolveClassComponentProps(ctor, unresolvedOldProps);
  instance.props = oldProps;
  const unresolvedNewProps = workInProgress.pendingProps;

  const oldContext = instance.context;
  const contextType = ctor.contextType;
  let nextContext = emptyContextObject;
  if (typeof contextType === 'object' && contextType !== null) {
    nextContext = readContext(contextType);
  } else if (!disableLegacyContext) {
    const nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
    nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  }

  const getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  const hasNewLifecycles =
    typeof getDerivedStateFromProps === 'function' ||
    typeof instance.getSnapshotBeforeUpdate === 'function';

  // Note: During these life-cycles, instance.props/instance.state are what
  // ever the previously attempted to render - not the "current". However,
  // during componentDidUpdate we pass the "current" props.

  // In order to support react-lifecycles-compat polyfilled components,
  // Unsafe lifecycles should not be invoked for components using the new APIs.
  if (
    !hasNewLifecycles &&
    (typeof instance.UNSAFE_componentWillReceiveProps === 'function' ||
      typeof instance.componentWillReceiveProps === 'function')
  ) {
    if (
      unresolvedOldProps !== unresolvedNewProps ||
      oldContext !== nextContext
    ) {
      callComponentWillReceiveProps(
        workInProgress,
        instance,
        newProps,
        nextContext,
      );
    }
  }

  resetHasForceUpdateBeforeProcessing();

  const oldState = workInProgress.memoizedState;
  let newState = (instance.state = oldState);
  processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  suspendIfUpdateReadFromEntangledAsyncAction();
  newState = workInProgress.memoizedState;

  if (
    unresolvedOldProps === unresolvedNewProps &&
    oldState === newState &&
    !hasContextChanged() &&
    !checkHasForceUpdateAfterProcessing() &&
    !(
      current !== null &&
      current.dependencies !== null &&
      checkIfContextChanged(current.dependencies)
    )
  ) {
    // If an update was already in progress, we should schedule an Update
    // effect even though we're bailing out, so that cWU/cDU are called.
    if (typeof instance.componentDidUpdate === 'function') {
      if (
        unresolvedOldProps !== current.memoizedProps ||
        oldState !== current.memoizedState
      ) {

Domain

Subdomains

Frequently Asked Questions

What does updateClassInstance() do?
updateClassInstance() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberClassComponent.js.
Where is updateClassInstance() defined?
updateClassInstance() is defined in packages/react-reconciler/src/ReactFiberClassComponent.js at line 1004.
What does updateClassInstance() call?
updateClassInstance() calls 4 function(s): applyDerivedStateFromProps, callComponentWillReceiveProps, checkShouldComponentUpdate, resolveClassComponentProps.
What calls updateClassInstance()?
updateClassInstance() is called by 1 function(s): updateClassComponent.

Analyze Your Own Codebase

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

Try Supermodel Free