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

Function constructClassInstance

code/communication/public/app.js:8403–8477  ·  view source on GitHub ↗
(workInProgress, props)

Source from the content-addressed store, hash-verified

8401 }
8402
8403 function constructClassInstance(workInProgress, props) {
8404 var ctor = workInProgress.type;
8405 var unmaskedContext = getUnmaskedContext(workInProgress);
8406 var needsContext = isContextConsumer(workInProgress);
8407 var context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject;
8408
8409 // Instantiate twice to help detect side-effects.
8410 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8411 new ctor(props, context); // eslint-disable-line no-new
8412 }
8413
8414 var instance = new ctor(props, context);
8415 var state = instance.state !== null && instance.state !== undefined ? instance.state : null;
8416 adoptClassInstance(workInProgress, instance);
8417
8418 {
8419 if (typeof ctor.getDerivedStateFromProps === 'function') {
8420 if (state === null) {
8421 var componentName = getComponentName(workInProgress) || 'Component';
8422 if (!didWarnAboutUninitializedState[componentName]) {
8423 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');
8424 didWarnAboutUninitializedState[componentName] = true;
8425 }
8426 }
8427
8428 // If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called.
8429 // Warn about these lifecycles if they are present.
8430 // Don't warn about react-lifecycles-compat polyfilled methods though.
8431 var foundWillMountName = null;
8432 var foundWillReceivePropsName = null;
8433 var foundWillUpdateName = null;
8434 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
8435 foundWillMountName = 'componentWillMount';
8436 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
8437 foundWillMountName = 'UNSAFE_componentWillMount';
8438 }
8439 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
8440 foundWillReceivePropsName = 'componentWillReceiveProps';
8441 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
8442 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
8443 }
8444 if (typeof instance.componentWillUpdate === 'function') {
8445 foundWillUpdateName = 'componentWillUpdate';
8446 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
8447 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
8448 }
8449 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
8450 var _componentName = getComponentName(workInProgress) || 'Component';
8451 if (!didWarnAboutLegacyLifecyclesAndDerivedState[_componentName]) {
8452 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 : '');
8453 didWarnAboutLegacyLifecyclesAndDerivedState[_componentName] = true;
8454 }
8455 }
8456 }
8457 }
8458
8459 workInProgress.memoizedState = state;
8460

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