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

Function createInstance

packages/react-noop-renderer/src/createReactNoop.js:399–453  ·  view source on GitHub ↗
(
      type: string,
      props: Props,
      rootContainerInstance: Container,
      hostContext: HostContext,
      internalInstanceHandle: Object,
    )

Source from the content-addressed store, hash-verified

397 },
398
399 createInstance(
400 type: string,
401 props: Props,
402 rootContainerInstance: Container,
403 hostContext: HostContext,
404 internalInstanceHandle: Object,
405 ): Instance {
406 if (type === 'errorInCompletePhase') {
407 throw new Error('Error in host config.');
408 }
409 if (__DEV__) {
410 // The `if` statement here prevents auto-disabling of the safe coercion
411 // ESLint rule, so we must manually disable it below.
412 if (shouldSetTextContent(type, props)) {
413 checkPropStringCoercion(props.children, 'children');
414 }
415 }
416 const inst = {
417 id: instanceCounter++,
418 type: type,
419 children: [],
420 parent: -1,
421 text: shouldSetTextContent(type, props)
422 ? // eslint-disable-next-line react-internal/safe-string-coercion
423 computeText((props.children: any) + '', hostContext)
424 : null,
425 prop: props.prop,
426 hidden: !!props.hidden,
427 context: hostContext,
428 };
429
430 if (type === 'suspensey-thing' && typeof props.src === 'string') {
431 inst.src = props.src;
432 }
433
434 // Hide from unit tests
435 Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false});
436 Object.defineProperty(inst, 'parent', {
437 value: inst.parent,
438 enumerable: false,
439 });
440 Object.defineProperty(inst, 'text', {
441 value: inst.text,
442 enumerable: false,
443 });
444 Object.defineProperty(inst, 'context', {
445 value: inst.context,
446 enumerable: false,
447 });
448 Object.defineProperty(inst, 'fiber', {
449 value: internalInstanceHandle,
450 enumerable: false,
451 });
452 return inst;
453 },
454
455 cloneMutableInstance(instance: Instance, keepChildren: boolean): Instance {
456 throw new Error('Not yet implemented.');

Callers

nothing calls this directly

Calls 3

checkPropStringCoercionFunction · 0.90
computeTextFunction · 0.85
shouldSetTextContentFunction · 0.70

Tested by

no test coverage detected