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

Function constructClassInstance

code/new-context-api/public/app.js:7729–7803  ·  view source on GitHub ↗
(workInProgress, props)

Source from the content-addressed store, hash-verified

7727 }
7728
7729 function constructClassInstance(workInProgress, props) {
7730 var ctor = workInProgress.type;
7731 var unmaskedContext = getUnmaskedContext(workInProgress);
7732 var needsContext = isContextConsumer(workInProgress);
7733 var context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject;
7734
7735 // Instantiate twice to help detect side-effects.
7736 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
7737 new ctor(props, context); // eslint-disable-line no-new
7738 }
7739
7740 var instance = new ctor(props, context);
7741 var state = instance.state !== null && instance.state !== undefined ? instance.state : null;
7742 adoptClassInstance(workInProgress, instance);
7743
7744 {
7745 if (typeof ctor.getDerivedStateFromProps === 'function') {
7746 if (state === null) {
7747 var componentName = getComponentName(workInProgress) || 'Component';
7748 if (!didWarnAboutUninitializedState[componentName]) {
7749 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');
7750 didWarnAboutUninitializedState[componentName] = true;
7751 }
7752 }
7753
7754 // If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called.
7755 // Warn about these lifecycles if they are present.
7756 // Don't warn about react-lifecycles-compat polyfilled methods though.
7757 var foundWillMountName = null;
7758 var foundWillReceivePropsName = null;
7759 var foundWillUpdateName = null;
7760 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
7761 foundWillMountName = 'componentWillMount';
7762 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
7763 foundWillMountName = 'UNSAFE_componentWillMount';
7764 }
7765 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
7766 foundWillReceivePropsName = 'componentWillReceiveProps';
7767 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
7768 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
7769 }
7770 if (typeof instance.componentWillUpdate === 'function') {
7771 foundWillUpdateName = 'componentWillUpdate';
7772 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
7773 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
7774 }
7775 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
7776 var _componentName = getComponentName(workInProgress) || 'Component';
7777 if (!didWarnAboutLegacyLifecyclesAndDerivedState[_componentName]) {
7778 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 : '');
7779 didWarnAboutLegacyLifecyclesAndDerivedState[_componentName] = true;
7780 }
7781 }
7782 }
7783 }
7784
7785 workInProgress.memoizedState = state;
7786

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