(workInProgress, props)
| 8617 | } |
| 8618 | |
| 8619 | function constructClassInstance(workInProgress, props) { |
| 8620 | var ctor = workInProgress.type; |
| 8621 | var unmaskedContext = getUnmaskedContext(workInProgress); |
| 8622 | var needsContext = isContextConsumer(workInProgress); |
| 8623 | var context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject; |
| 8624 | |
| 8625 | // Instantiate twice to help detect side-effects. |
| 8626 | if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) { |
| 8627 | new ctor(props, context); // eslint-disable-line no-new |
| 8628 | } |
| 8629 | |
| 8630 | var instance = new ctor(props, context); |
| 8631 | var state = instance.state !== null && instance.state !== undefined ? instance.state : null; |
| 8632 | adoptClassInstance(workInProgress, instance); |
| 8633 | |
| 8634 | { |
| 8635 | if (typeof ctor.getDerivedStateFromProps === 'function') { |
| 8636 | if (state === null) { |
| 8637 | var componentName = getComponentName(workInProgress) || 'Component'; |
| 8638 | if (!didWarnAboutUninitializedState[componentName]) { |
| 8639 | 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'); |
| 8640 | didWarnAboutUninitializedState[componentName] = true; |
| 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | // If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called. |
| 8645 | // Warn about these lifecycles if they are present. |
| 8646 | // Don't warn about react-lifecycles-compat polyfilled methods though. |
| 8647 | var foundWillMountName = null; |
| 8648 | var foundWillReceivePropsName = null; |
| 8649 | var foundWillUpdateName = null; |
| 8650 | if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) { |
| 8651 | foundWillMountName = 'componentWillMount'; |
| 8652 | } else if (typeof instance.UNSAFE_componentWillMount === 'function') { |
| 8653 | foundWillMountName = 'UNSAFE_componentWillMount'; |
| 8654 | } |
| 8655 | if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) { |
| 8656 | foundWillReceivePropsName = 'componentWillReceiveProps'; |
| 8657 | } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') { |
| 8658 | foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps'; |
| 8659 | } |
| 8660 | if (typeof instance.componentWillUpdate === 'function') { |
| 8661 | foundWillUpdateName = 'componentWillUpdate'; |
| 8662 | } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') { |
| 8663 | foundWillUpdateName = 'UNSAFE_componentWillUpdate'; |
| 8664 | } |
| 8665 | if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) { |
| 8666 | var _componentName = getComponentName(workInProgress) || 'Component'; |
| 8667 | if (!didWarnAboutLegacyLifecyclesAndDerivedState[_componentName]) { |
| 8668 | 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 : ''); |
| 8669 | didWarnAboutLegacyLifecyclesAndDerivedState[_componentName] = true; |
| 8670 | } |
| 8671 | } |
| 8672 | } |
| 8673 | } |
| 8674 | |
| 8675 | workInProgress.memoizedState = state; |
| 8676 |
no test coverage detected