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

Function setProp

packages/react-dom-bindings/src/client/ReactDOMComponent.js:341–939  ·  view source on GitHub ↗
(
  domElement: Element,
  tag: string,
  key: string,
  value: mixed,
  props: any,
  prevValue: mixed,
)

Source from the content-addressed store, hash-verified

339const xmlNamespace = 'http://www.w3.org/XML/1998/namespace';
340
341function setProp(
342 domElement: Element,
343 tag: string,
344 key: string,
345 value: mixed,
346 props: any,
347 prevValue: mixed,
348): void {
349 switch (key) {
350 case 'children': {
351 if (typeof value === 'string') {
352 if (__DEV__) {
353 validateTextNesting(value, tag, false);
354 }
355 // Avoid setting initial textContent when the text is empty. In IE11 setting
356 // textContent on a <textarea> will cause the placeholder to not
357 // show within the <textarea> until it has been focused and blurred again.
358 // https://github.com/facebook/react/issues/6731#issuecomment-254874553
359 const canSetTextContent =
360 tag !== 'body' && (tag !== 'textarea' || value !== '');
361 if (canSetTextContent) {
362 setTextContent(domElement, value);
363 }
364 } else if (typeof value === 'number' || typeof value === 'bigint') {
365 if (__DEV__) {
366 // $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint
367 validateTextNesting('' + value, tag, false);
368 }
369 const canSetTextContent = tag !== 'body';
370 if (canSetTextContent) {
371 // $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint
372 setTextContent(domElement, '' + value);
373 }
374 } else {
375 return;
376 }
377 break;
378 }
379 // These are very common props and therefore are in the beginning of the switch.
380 // TODO: aria-label is a very common prop but allows booleans so is not like the others
381 // but should ideally go in this list too.
382 case 'className':
383 setValueForKnownAttribute(domElement, 'class', value);
384 break;
385 case 'tabIndex':
386 // This has to be case sensitive in SVG.
387 setValueForKnownAttribute(domElement, 'tabindex', value);
388 break;
389 case 'dir':
390 case 'role':
391 case 'viewBox':
392 case 'width':
393 case 'height': {
394 setValueForKnownAttribute(domElement, key, value);
395 break;
396 }
397 case 'style': {
398 setValueForStyles(domElement, value, prevValue);

Callers 2

setInitialPropertiesFunction · 0.85
updatePropertiesFunction · 0.85

Calls 15

validateTextNestingFunction · 0.90
setValueForStylesFunction · 0.90
setSrcObjectFunction · 0.90
setValueForAttributeFunction · 0.90
trackHostMutationFunction · 0.90
setTextContentFunction · 0.85
sanitizeURLFunction · 0.85

Tested by

no test coverage detected