MCPcopy
hub / github.com/facebook/react / checkClassInstance

Function checkClassInstance

packages/react-server/src/ReactFizzClassComponent.js:313–542  ·  view source on GitHub ↗
(instance: any, ctor: any, newProps: any)

Source from the content-addressed store, hash-verified

311}
312
313function checkClassInstance(instance: any, ctor: any, newProps: any) {
314 if (__DEV__) {
315 const name = getComponentNameFromType(ctor) || 'Component';
316 const renderPresent = instance.render;
317
318 if (!renderPresent) {
319 if (ctor.prototype && typeof ctor.prototype.render === 'function') {
320 console.error(
321 'No `render` method found on the %s ' +
322 'instance: did you accidentally return an object from the constructor?',
323 name,
324 );
325 } else {
326 console.error(
327 'No `render` method found on the %s ' +
328 'instance: you may have forgotten to define `render`.',
329 name,
330 );
331 }
332 }
333
334 if (
335 instance.getInitialState &&
336 !instance.getInitialState.isReactClassApproved &&
337 !instance.state
338 ) {
339 console.error(
340 'getInitialState was defined on %s, a plain JavaScript class. ' +
341 'This is only supported for classes created using React.createClass. ' +
342 'Did you mean to define a state property instead?',
343 name,
344 );
345 }
346 if (
347 instance.getDefaultProps &&
348 !instance.getDefaultProps.isReactClassApproved
349 ) {
350 console.error(
351 'getDefaultProps was defined on %s, a plain JavaScript class. ' +
352 'This is only supported for classes created using React.createClass. ' +
353 'Use a static property to define defaultProps instead.',
354 name,
355 );
356 }
357 if (instance.contextType) {
358 console.error(
359 'contextType was defined as an instance property on %s. Use a static ' +
360 'property to define contextType instead.',
361 name,
362 );
363 }
364
365 if (disableLegacyContext) {
366 if (ctor.childContextTypes && !didWarnAboutChildContextTypes.has(ctor)) {
367 didWarnAboutChildContextTypes.add(ctor);
368 console.error(
369 '%s uses the legacy childContextTypes API which was removed in React 19. ' +
370 'Use React.createContext() instead. (https://react.dev/link/legacy-context)',

Callers 1

mountClassInstanceFunction · 0.70

Calls 5

getComponentNameFromTypeFunction · 0.85
isArrayFunction · 0.85
addMethod · 0.80
errorMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected