(workInProgress, ctor, newProps, renderLanes)
| 18329 | |
| 18330 | |
| 18331 | function mountClassInstance(workInProgress, ctor, newProps, renderLanes) { |
| 18332 | { |
| 18333 | checkClassInstance(workInProgress, ctor, newProps); |
| 18334 | } |
| 18335 | |
| 18336 | var instance = workInProgress.stateNode; |
| 18337 | instance.props = newProps; |
| 18338 | instance.state = workInProgress.memoizedState; |
| 18339 | instance.refs = {}; |
| 18340 | initializeUpdateQueue(workInProgress); |
| 18341 | var contextType = ctor.contextType; |
| 18342 | |
| 18343 | if (typeof contextType === 'object' && contextType !== null) { |
| 18344 | instance.context = readContext(contextType); |
| 18345 | } else { |
| 18346 | var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); |
| 18347 | instance.context = getMaskedContext(workInProgress, unmaskedContext); |
| 18348 | } |
| 18349 | |
| 18350 | { |
| 18351 | if (instance.state === newProps) { |
| 18352 | var componentName = getComponentNameFromType(ctor) || 'Component'; |
| 18353 | |
| 18354 | if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { |
| 18355 | didWarnAboutDirectlyAssigningPropsToState.add(componentName); |
| 18356 | |
| 18357 | error('%s: It is not recommended to assign props directly to state ' + "because updates to props won't be reflected in state. " + 'In most cases, it is better to use props directly.', componentName); |
| 18358 | } |
| 18359 | } |
| 18360 | |
| 18361 | if (workInProgress.mode & StrictLegacyMode) { |
| 18362 | ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance); |
| 18363 | } |
| 18364 | |
| 18365 | { |
| 18366 | ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance); |
| 18367 | } |
| 18368 | } |
| 18369 | |
| 18370 | instance.state = workInProgress.memoizedState; |
| 18371 | var getDerivedStateFromProps = ctor.getDerivedStateFromProps; |
| 18372 | |
| 18373 | if (typeof getDerivedStateFromProps === 'function') { |
| 18374 | applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps); |
| 18375 | instance.state = workInProgress.memoizedState; |
| 18376 | } // In order to support react-lifecycles-compat polyfilled components, |
| 18377 | // Unsafe lifecycles should not be invoked for components using the new APIs. |
| 18378 | |
| 18379 | |
| 18380 | if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) { |
| 18381 | callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's |
| 18382 | // process them now. |
| 18383 | |
| 18384 | processUpdateQueue(workInProgress, newProps, instance, renderLanes); |
| 18385 | instance.state = workInProgress.memoizedState; |
| 18386 | } |
| 18387 | |
| 18388 | if (typeof instance.componentDidMount === 'function') { |
no test coverage detected
searching dependent graphs…