MCPcopy
hub / github.com/plotly/dash / constructClassInstance

Function constructClassInstance

dash/deps/react-dom@18.2.0.js:14291–14408  ·  view source on GitHub ↗
(workInProgress, ctor, props)

Source from the content-addressed store, hash-verified

14289 }
14290
14291 function constructClassInstance(workInProgress, ctor, props) {
14292 var isLegacyContextConsumer = false;
14293 var unmaskedContext = emptyContextObject;
14294 var context = emptyContextObject;
14295 var contextType = ctor.contextType;
14296
14297 {
14298 if ('contextType' in ctor) {
14299 var isValid = // Allow null for conditional declaration
14300 contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
14301
14302 if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
14303 didWarnAboutInvalidateContextType.add(ctor);
14304 var addendum = '';
14305
14306 if (contextType === undefined) {
14307 addendum = ' However, it is set to undefined. ' + 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, so ' + 'try moving the createContext() call to a separate file.';
14308 } else if (typeof contextType !== 'object') {
14309 addendum = ' However, it is set to a ' + typeof contextType + '.';
14310 } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
14311 addendum = ' Did you accidentally pass the Context.Provider instead?';
14312 } else if (contextType._context !== undefined) {
14313 // <Context.Consumer>
14314 addendum = ' Did you accidentally pass the Context.Consumer instead?';
14315 } else {
14316 addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
14317 }
14318
14319 error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentNameFromType(ctor) || 'Component', addendum);
14320 }
14321 }
14322 }
14323
14324 if (typeof contextType === 'object' && contextType !== null) {
14325 context = readContext(contextType);
14326 } else {
14327 unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
14328 var contextTypes = ctor.contextTypes;
14329 isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
14330 context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
14331 }
14332
14333 var instance = new ctor(props, context); // Instantiate twice to help detect side-effects.
14334
14335 {
14336 if ( workInProgress.mode & StrictLegacyMode) {
14337 setIsStrictModeForDevtools(true);
14338
14339 try {
14340 instance = new ctor(props, context); // eslint-disable-line no-new
14341 } finally {
14342 setIsStrictModeForDevtools(false);
14343 }
14344 }
14345 }
14346
14347 var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
14348 adoptClassInstance(workInProgress, instance);

Callers 2

updateClassComponentFunction · 0.70

Calls 10

keysMethod · 0.80
errorFunction · 0.70
getComponentNameFromTypeFunction · 0.70
readContextFunction · 0.70
getUnmaskedContextFunction · 0.70
getMaskedContextFunction · 0.70
adoptClassInstanceFunction · 0.70
cacheContextFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…