MCPcopy Index your code
hub / github.com/react/react / mountClassInstance

Function mountClassInstance

packages/react-reconciler/src/ReactFiberClassComponent.js:761–850  ·  view source on GitHub ↗
(
  workInProgress: Fiber,
  ctor: any,
  newProps: any,
  renderLanes: Lanes,
)

Source from the content-addressed store, hash-verified

759
760// Invokes the mount life-cycles on a previously never rendered instance.
761function mountClassInstance(
762 workInProgress: Fiber,
763 ctor: any,
764 newProps: any,
765 renderLanes: Lanes,
766): void {
767 if (__DEV__) {
768 checkClassInstance(workInProgress, ctor, newProps);
769 }
770
771 const instance = workInProgress.stateNode;
772 instance.props = newProps;
773 instance.state = workInProgress.memoizedState;
774 instance.refs = {};
775
776 initializeUpdateQueue(workInProgress);
777
778 const contextType = ctor.contextType;
779 if (typeof contextType === 'object' && contextType !== null) {
780 instance.context = readContext(contextType);
781 } else if (disableLegacyContext) {
782 instance.context = emptyContextObject;
783 } else {
784 const unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
785 instance.context = getMaskedContext(workInProgress, unmaskedContext);
786 }
787
788 if (__DEV__) {
789 if (instance.state === newProps) {
790 const componentName = getComponentNameFromType(ctor) || 'Component';
791 if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
792 didWarnAboutDirectlyAssigningPropsToState.add(componentName);
793 console.error(
794 '%s: It is not recommended to assign props directly to state ' +
795 "because updates to props won't be reflected in state. " +
796 'In most cases, it is better to use props directly.',
797 componentName,
798 );
799 }
800 }
801
802 if (workInProgress.mode & StrictLegacyMode) {
803 ReactStrictModeWarnings.recordLegacyContextWarning(
804 workInProgress,
805 instance,
806 );
807 }
808
809 ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
810 workInProgress,
811 instance,
812 );
813 }
814
815 instance.state = workInProgress.memoizedState;
816
817 const getDerivedStateFromProps = ctor.getDerivedStateFromProps;
818 if (typeof getDerivedStateFromProps === 'function') {

Callers 2

updateClassComponentFunction · 0.90

Calls 13

initializeUpdateQueueFunction · 0.90
readContextFunction · 0.90
getUnmaskedContextFunction · 0.90
getMaskedContextFunction · 0.90
processUpdateQueueFunction · 0.90
getComponentNameFromTypeFunction · 0.85
addMethod · 0.80
checkClassInstanceFunction · 0.70
callComponentWillMountFunction · 0.70
hasMethod · 0.65

Tested by

no test coverage detected