( ctor: any, props: any, maskedLegacyContext: any, )
| 168 | } |
| 169 | |
| 170 | export function constructClassInstance( |
| 171 | ctor: any, |
| 172 | props: any, |
| 173 | maskedLegacyContext: any, |
| 174 | ): any { |
| 175 | let context = emptyContextObject; |
| 176 | const contextType = ctor.contextType; |
| 177 | |
| 178 | if (__DEV__) { |
| 179 | if ('contextType' in ctor) { |
| 180 | const isValid = |
| 181 | // Allow null for conditional declaration |
| 182 | contextType === null || |
| 183 | (contextType !== undefined && |
| 184 | contextType.$$typeof === REACT_CONTEXT_TYPE); |
| 185 | |
| 186 | if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) { |
| 187 | didWarnAboutInvalidateContextType.add(ctor); |
| 188 | |
| 189 | let addendum = ''; |
| 190 | if (contextType === undefined) { |
| 191 | addendum = |
| 192 | ' However, it is set to undefined. ' + |
| 193 | 'This can be caused by a typo or by mixing up named and default imports. ' + |
| 194 | 'This can also happen due to a circular dependency, so ' + |
| 195 | 'try moving the createContext() call to a separate file.'; |
| 196 | } else if (typeof contextType !== 'object') { |
| 197 | addendum = ' However, it is set to a ' + typeof contextType + '.'; |
| 198 | } else if (contextType.$$typeof === REACT_CONSUMER_TYPE) { |
| 199 | addendum = ' Did you accidentally pass the Context.Consumer instead?'; |
| 200 | } else { |
| 201 | addendum = |
| 202 | ' However, it is set to an object with keys {' + |
| 203 | Object.keys(contextType).join(', ') + |
| 204 | '}.'; |
| 205 | } |
| 206 | console.error( |
| 207 | '%s defines an invalid contextType. ' + |
| 208 | 'contextType should point to the Context object returned by React.createContext().%s', |
| 209 | getComponentNameFromType(ctor) || 'Component', |
| 210 | addendum, |
| 211 | ); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | if (typeof contextType === 'object' && contextType !== null) { |
| 217 | context = readContext((contextType: any)); |
| 218 | } else if (!disableLegacyContext) { |
| 219 | context = maskedLegacyContext; |
| 220 | } |
| 221 | |
| 222 | const instance = new ctor(props, context); |
| 223 | |
| 224 | if (__DEV__) { |
| 225 | if ( |
| 226 | typeof ctor.getDerivedStateFromProps === 'function' && |
| 227 | (instance.state === null || instance.state === undefined) |
no test coverage detected