(workInProgress, props)
| 8366 | } |
| 8367 | |
| 8368 | function constructClassInstance(workInProgress, props) { |
| 8369 | var ctor = workInProgress.type; |
| 8370 | var unmaskedContext = getUnmaskedContext(workInProgress); |
| 8371 | var needsContext = isContextConsumer(workInProgress); |
| 8372 | var context = needsContext ? getMaskedContext(workInProgress, unmaskedContext) : emptyObject; |
| 8373 | |
| 8374 | // Instantiate twice to help detect side-effects. |
| 8375 | if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) { |
| 8376 | new ctor(props, context); // eslint-disable-line no-new |
| 8377 | } |
| 8378 | |
| 8379 | var instance = new ctor(props, context); |
| 8380 | var state = instance.state !== null && instance.state !== undefined ? instance.state : null; |
| 8381 | adoptClassInstance(workInProgress, instance); |
| 8382 | |
| 8383 | { |
| 8384 | if (typeof ctor.getDerivedStateFromProps === 'function') { |
| 8385 | if (state === null) { |
| 8386 | var componentName = getComponentName(workInProgress) || 'Component'; |
| 8387 | if (!didWarnAboutUninitializedState[componentName]) { |
| 8388 | 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'); |
| 8389 | didWarnAboutUninitializedState[componentName] = true; |
| 8390 | } |
| 8391 | } |
| 8392 | |
| 8393 | // If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called. |
| 8394 | // Warn about these lifecycles if they are present. |
| 8395 | // Don't warn about react-lifecycles-compat polyfilled methods though. |
| 8396 | var foundWillMountName = null; |
| 8397 | var foundWillReceivePropsName = null; |
| 8398 | var foundWillUpdateName = null; |
| 8399 | if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) { |
| 8400 | foundWillMountName = 'componentWillMount'; |
| 8401 | } else if (typeof instance.UNSAFE_componentWillMount === 'function') { |
| 8402 | foundWillMountName = 'UNSAFE_componentWillMount'; |
| 8403 | } |
| 8404 | if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) { |
| 8405 | foundWillReceivePropsName = 'componentWillReceiveProps'; |
| 8406 | } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') { |
| 8407 | foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps'; |
| 8408 | } |
| 8409 | if (typeof instance.componentWillUpdate === 'function') { |
| 8410 | foundWillUpdateName = 'componentWillUpdate'; |
| 8411 | } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') { |
| 8412 | foundWillUpdateName = 'UNSAFE_componentWillUpdate'; |
| 8413 | } |
| 8414 | if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) { |
| 8415 | var _componentName = getComponentName(workInProgress) || 'Component'; |
| 8416 | if (!didWarnAboutLegacyLifecyclesAndDerivedState[_componentName]) { |
| 8417 | 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 : ''); |
| 8418 | didWarnAboutLegacyLifecyclesAndDerivedState[_componentName] = true; |
| 8419 | } |
| 8420 | } |
| 8421 | } |
| 8422 | } |
| 8423 | |
| 8424 | workInProgress.memoizedState = state; |
| 8425 |
no test coverage detected