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

Function constructClassInstance

code/composition/public/app.js:8506–8580  ·  view source on GitHub ↗
(workInProgress, props)

Source from the content-addressed store, hash-verified

8504 }
8505
8506 function constructClassInstance(workInProgress, props) {
8507 var ctor = workInProgress.type;
8508 var unmaskedContext = getUnmaskedContext(workInProgress);
8509 var needsContext = isContextConsumer(workInProgress);
8510 var context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject;
8511
8512 // Instantiate twice to help detect side-effects.
8513 if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
8514 new ctor(props, context); // eslint-disable-line no-new
8515 }
8516
8517 var instance = new ctor(props, context);
8518 var state = instance.state !== null && instance.state !== undefined ? instance.state : null;
8519 adoptClassInstance(workInProgress, instance);
8520
8521 {
8522 if (typeof ctor.getDerivedStateFromProps === 'function') {
8523 if (state === null) {
8524 var componentName = getComponentName(workInProgress) || 'Component';
8525 if (!didWarnAboutUninitializedState[componentName]) {
8526 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');
8527 didWarnAboutUninitializedState[componentName] = true;
8528 }
8529 }
8530
8531 // If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called.
8532 // Warn about these lifecycles if they are present.
8533 // Don't warn about react-lifecycles-compat polyfilled methods though.
8534 var foundWillMountName = null;
8535 var foundWillReceivePropsName = null;
8536 var foundWillUpdateName = null;
8537 if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
8538 foundWillMountName = 'componentWillMount';
8539 } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
8540 foundWillMountName = 'UNSAFE_componentWillMount';
8541 }
8542 if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
8543 foundWillReceivePropsName = 'componentWillReceiveProps';
8544 } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
8545 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
8546 }
8547 if (typeof instance.componentWillUpdate === 'function') {
8548 foundWillUpdateName = 'componentWillUpdate';
8549 } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
8550 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
8551 }
8552 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
8553 var _componentName = getComponentName(workInProgress) || 'Component';
8554 if (!didWarnAboutLegacyLifecyclesAndDerivedState[_componentName]) {
8555 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 : '');
8556 didWarnAboutLegacyLifecyclesAndDerivedState[_componentName] = true;
8557 }
8558 }
8559 }
8560 }
8561
8562 workInProgress.memoizedState = state;
8563

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