( workInProgress: Fiber, ctor: any, newProps: any, renderLanes: Lanes, )
| 759 | |
| 760 | // Invokes the mount life-cycles on a previously never rendered instance. |
| 761 | function mountClassInstance( |
| 762 | workInProgress: Fiber, |
| 763 | ctor: any, |
| 764 | newProps: any, |
| 765 | renderLanes: Lanes, |
| 766 | ): void { |
| 767 | if (__DEV__) { |
| 768 | checkClassInstance(workInProgress, ctor, newProps); |
| 769 | } |
| 770 | |
| 771 | const instance = workInProgress.stateNode; |
| 772 | instance.props = newProps; |
| 773 | instance.state = workInProgress.memoizedState; |
| 774 | instance.refs = {}; |
| 775 | |
| 776 | initializeUpdateQueue(workInProgress); |
| 777 | |
| 778 | const contextType = ctor.contextType; |
| 779 | if (typeof contextType === 'object' && contextType !== null) { |
| 780 | instance.context = readContext(contextType); |
| 781 | } else if (disableLegacyContext) { |
| 782 | instance.context = emptyContextObject; |
| 783 | } else { |
| 784 | const unmaskedContext = getUnmaskedContext(workInProgress, ctor, true); |
| 785 | instance.context = getMaskedContext(workInProgress, unmaskedContext); |
| 786 | } |
| 787 | |
| 788 | if (__DEV__) { |
| 789 | if (instance.state === newProps) { |
| 790 | const componentName = getComponentNameFromType(ctor) || 'Component'; |
| 791 | if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) { |
| 792 | didWarnAboutDirectlyAssigningPropsToState.add(componentName); |
| 793 | console.error( |
| 794 | '%s: It is not recommended to assign props directly to state ' + |
| 795 | "because updates to props won't be reflected in state. " + |
| 796 | 'In most cases, it is better to use props directly.', |
| 797 | componentName, |
| 798 | ); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | if (workInProgress.mode & StrictLegacyMode) { |
| 803 | ReactStrictModeWarnings.recordLegacyContextWarning( |
| 804 | workInProgress, |
| 805 | instance, |
| 806 | ); |
| 807 | } |
| 808 | |
| 809 | ReactStrictModeWarnings.recordUnsafeLifecycleWarnings( |
| 810 | workInProgress, |
| 811 | instance, |
| 812 | ); |
| 813 | } |
| 814 | |
| 815 | instance.state = workInProgress.memoizedState; |
| 816 | |
| 817 | const getDerivedStateFromProps = ctor.getDerivedStateFromProps; |
| 818 | if (typeof getDerivedStateFromProps === 'function') { |
no test coverage detected