Home / Function/ applyDerivedStateFromProps() — react Function Reference

applyDerivedStateFromProps() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  9f4500d1_a30b_b3dc_2405_2ab2117c51e4["applyDerivedStateFromProps()"]
  3805476a_1924_0e35_fff7_6afad197a523["ReactFiberClassComponent.js"]
  9f4500d1_a30b_b3dc_2405_2ab2117c51e4 -->|defined in| 3805476a_1924_0e35_fff7_6afad197a523
  3d21bb44_e12a_666f_ff91_4155c0f8d71b["mountClassInstance()"]
  3d21bb44_e12a_666f_ff91_4155c0f8d71b -->|calls| 9f4500d1_a30b_b3dc_2405_2ab2117c51e4
  40e9392c_b382_4ef8_9ede_8ac85559673c["resumeMountClassInstance()"]
  40e9392c_b382_4ef8_9ede_8ac85559673c -->|calls| 9f4500d1_a30b_b3dc_2405_2ab2117c51e4
  d93c8e6d_2cc8_2077_fe19_1d954fc83959["updateClassInstance()"]
  d93c8e6d_2cc8_2077_fe19_1d954fc83959 -->|calls| 9f4500d1_a30b_b3dc_2405_2ab2117c51e4
  88d91075_df31_e6fc_5535_80030045f42a["setIsStrictModeForDevtools()"]
  9f4500d1_a30b_b3dc_2405_2ab2117c51e4 -->|calls| 88d91075_df31_e6fc_5535_80030045f42a
  659d9471_e821_a589_6978_568ced15f6d2["warnOnUndefinedDerivedState()"]
  9f4500d1_a30b_b3dc_2405_2ab2117c51e4 -->|calls| 659d9471_e821_a589_6978_568ced15f6d2
  style 9f4500d1_a30b_b3dc_2405_2ab2117c51e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-reconciler/src/ReactFiberClassComponent.js lines 129–163

function applyDerivedStateFromProps(
  workInProgress: Fiber,
  ctor: any,
  getDerivedStateFromProps: (props: any, state: any) => any,
  nextProps: any,
) {
  const prevState = workInProgress.memoizedState;
  let partialState = getDerivedStateFromProps(nextProps, prevState);
  if (__DEV__) {
    if (workInProgress.mode & StrictLegacyMode) {
      setIsStrictModeForDevtools(true);
      try {
        // Invoke the function an extra time to help detect side-effects.
        partialState = getDerivedStateFromProps(nextProps, prevState);
      } finally {
        setIsStrictModeForDevtools(false);
      }
    }
    warnOnUndefinedDerivedState(ctor, partialState);
  }
  // Merge the partial state and the previous state.
  const memoizedState =
    partialState === null || partialState === undefined
      ? prevState
      : assign({}, prevState, partialState);
  workInProgress.memoizedState = memoizedState;

  // Once the update queue is empty, persist the derived state onto the
  // base state.
  if (workInProgress.lanes === NoLanes) {
    // Queue is always non-null for classes
    const updateQueue: UpdateQueue<any> = (workInProgress.updateQueue: any);
    updateQueue.baseState = memoizedState;
  }
}

Domain

Subdomains

Frequently Asked Questions

What does applyDerivedStateFromProps() do?
applyDerivedStateFromProps() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberClassComponent.js.
Where is applyDerivedStateFromProps() defined?
applyDerivedStateFromProps() is defined in packages/react-reconciler/src/ReactFiberClassComponent.js at line 129.
What does applyDerivedStateFromProps() call?
applyDerivedStateFromProps() calls 2 function(s): setIsStrictModeForDevtools, warnOnUndefinedDerivedState.
What calls applyDerivedStateFromProps()?
applyDerivedStateFromProps() is called by 3 function(s): mountClassInstance, resumeMountClassInstance, updateClassInstance.

Analyze Your Own Codebase

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

Try Supermodel Free