mountClassInstance() — react Function Reference
Architecture documentation for the mountClassInstance() function in ReactFizzClassComponent.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 214e29b1_8411_c0df_65fc_dabe157ff86e["mountClassInstance()"] 8f850c79_0562_f37f_80ff_563c50cd0996["ReactFizzClassComponent.js"] 214e29b1_8411_c0df_65fc_dabe157ff86e -->|defined in| 8f850c79_0562_f37f_80ff_563c50cd0996 21ed4638_6bbb_68b6_932b_c6d5a9608876["checkClassInstance()"] 214e29b1_8411_c0df_65fc_dabe157ff86e -->|calls| 21ed4638_6bbb_68b6_932b_c6d5a9608876 6749ca7d_7c02_a31f_a37b_23a73ecf80be["applyDerivedStateFromProps()"] 214e29b1_8411_c0df_65fc_dabe157ff86e -->|calls| 6749ca7d_7c02_a31f_a37b_23a73ecf80be 3867b5d4_e231_02e6_8a86_90d620156f07["callComponentWillMount()"] 214e29b1_8411_c0df_65fc_dabe157ff86e -->|calls| 3867b5d4_e231_02e6_8a86_90d620156f07 bd96449d_3822_0ea5_878f_70fab765cc32["processUpdateQueue()"] 214e29b1_8411_c0df_65fc_dabe157ff86e -->|calls| bd96449d_3822_0ea5_878f_70fab765cc32 style 214e29b1_8411_c0df_65fc_dabe157ff86e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-server/src/ReactFizzClassComponent.js lines 626–703
export function mountClassInstance(
instance: any,
ctor: any,
newProps: any,
maskedLegacyContext: any,
): void {
if (__DEV__) {
checkClassInstance(instance, ctor, newProps);
}
const initialState = instance.state !== undefined ? instance.state : null;
instance.updater = classComponentUpdater;
instance.props = newProps;
instance.state = initialState;
// We don't bother initializing the refs object on the server, since we're not going to resolve them anyway.
// The internal instance will be used to manage updates that happen during this mount.
const internalInstance: InternalInstance = {
queue: [],
replace: false,
};
setInstance(instance, internalInstance);
const contextType = ctor.contextType;
if (typeof contextType === 'object' && contextType !== null) {
instance.context = readContext(contextType);
} else if (disableLegacyContext) {
instance.context = emptyContextObject;
} else {
instance.context = maskedLegacyContext;
}
if (__DEV__) {
if (instance.state === newProps) {
const componentName = getComponentNameFromType(ctor) || 'Component';
if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
didWarnAboutDirectlyAssigningPropsToState.add(componentName);
console.error(
'%s: It is not recommended to assign props directly to state ' +
"because updates to props won't be reflected in state. " +
'In most cases, it is better to use props directly.',
componentName,
);
}
}
}
const getDerivedStateFromProps = ctor.getDerivedStateFromProps;
if (typeof getDerivedStateFromProps === 'function') {
instance.state = applyDerivedStateFromProps(
instance,
ctor,
getDerivedStateFromProps,
initialState,
newProps,
);
}
// In order to support react-lifecycles-compat polyfilled components,
// Unsafe lifecycles should not be invoked for components using the new APIs.
if (
typeof ctor.getDerivedStateFromProps !== 'function' &&
typeof instance.getSnapshotBeforeUpdate !== 'function' &&
(typeof instance.UNSAFE_componentWillMount === 'function' ||
typeof instance.componentWillMount === 'function')
) {
callComponentWillMount(ctor, instance);
// If we had additional state updates during this life-cycle, let's
// process them now.
processUpdateQueue(
internalInstance,
instance,
newProps,
maskedLegacyContext,
);
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does mountClassInstance() do?
mountClassInstance() is a function in the react codebase, defined in packages/react-server/src/ReactFizzClassComponent.js.
Where is mountClassInstance() defined?
mountClassInstance() is defined in packages/react-server/src/ReactFizzClassComponent.js at line 626.
What does mountClassInstance() call?
mountClassInstance() calls 4 function(s): applyDerivedStateFromProps, callComponentWillMount, checkClassInstance, processUpdateQueue.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free