MCPcopy
hub / github.com/krasimir/react-in-patterns / constructClassInstance

Function constructClassInstance

code/event-handlers/public/app.js:7698–7772  ·  view source on GitHub ↗
(workInProgress, props)

Source from the content-addressed store, hash-verified

7696 }
7697
7698 function constructClassInstance(workInProgress, props) {
7699 var ctor = workInProgress.type;
7700 var unmaskedContext = getUnmaskedContext(workInProgress);
7701 var needsContext = isContextConsumer(workInProgress);
7702 var context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject;
7703
7704 // Instantiate twice to help detect side-effects.
7705 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
7706 new ctor(props, context); // eslint-disable-line no-new
7707 }
7708
7709 var instance = new ctor(props, context);
7710 var state = instance.state !== null && instance.state !== undefined ? instance.state : null;
7711 adoptClassInstance(workInProgress, instance);
7712
7713 {
7714 if (typeof ctor.getDerivedStateFromProps === 'function') {
7715 if (state === null) {
7716 var componentName = getComponentName(workInProgress) || 'Component';
7717 if (!didWarnAboutUninitializedState[componentName]) {
7718 warning(false, '%s: Did not properly initialize state during construction. ' + 'Expected state to be an object, but it was %s.', componentName, instance.state === null ? 'null' : 'undefined');
7719 didWarnAboutUninitializedState[componentName] = true;
7720 }
7721 }
7722
7723 // If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called.
7724 // Warn about these lifecycles if they are present.
7725 // Don't warn about react-lifecycles-compat polyfilled methods though.
7726 var foundWillMountName = null;
7727 var foundWillReceivePropsName = null;
7728 var foundWillUpdateName = null;
7729 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
7730 foundWillMountName = 'componentWillMount';
7731 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
7732 foundWillMountName = 'UNSAFE_componentWillMount';
7733 }
7734 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
7735 foundWillReceivePropsName = 'componentWillReceiveProps';
7736 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
7737 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
7738 }
7739 if (typeof instance.componentWillUpdate === 'function') {
7740 foundWillUpdateName = 'componentWillUpdate';
7741 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
7742 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
7743 }
7744 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
7745 var _componentName = getComponentName(workInProgress) || 'Component';
7746 if (!didWarnAboutLegacyLifecyclesAndDerivedState[_componentName]) {
7747 warning(false, 'Unsafe legacy lifecycles will not be called for components using ' + 'the new getDerivedStateFromProps() API.\n\n' + '%s uses getDerivedStateFromProps() but also contains the following legacy lifecycles:' + '%s%s%s\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-async-component-lifecycle-hooks', _componentName, foundWillMountName !== null ? '\n ' + foundWillMountName : '', foundWillReceivePropsName !== null ? '\n ' + foundWillReceivePropsName : '', foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '');
7748 didWarnAboutLegacyLifecyclesAndDerivedState[_componentName] = true;
7749 }
7750 }
7751 }
7752 }
7753
7754 workInProgress.memoizedState = state;
7755

Callers 1

updateClassComponentFunction · 0.70

Calls 8

warningFunction · 0.85
getUnmaskedContextFunction · 0.70
isContextConsumerFunction · 0.70
getMaskedContextFunction · 0.70
adoptClassInstanceFunction · 0.70
getComponentNameFunction · 0.70
cacheContextFunction · 0.70

Tested by

no test coverage detected