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

Function setTextContent

packages/react-dom-bindings/src/client/setTextContent.js:21–35  ·  view source on GitHub ↗

* Set the textContent property of a node. For text updates, it's faster * to set the `nodeValue` of the Text node directly instead of using * `.textContent` which will remove the existing node and create a new one. * * @param {DOMElement} node * @param {string} text * @internal

(node: Element, text: string)

Source from the content-addressed store, hash-verified

19 * @internal
20 */
21function setTextContent(node: Element, text: string): void {
22 if (text) {
23 const firstChild = node.firstChild;
24
25 if (
26 firstChild &&
27 firstChild === node.lastChild &&
28 firstChild.nodeType === TEXT_NODE
29 ) {
30 firstChild.nodeValue = text;
31 return;
32 }
33 }
34 node.textContent = text;
35}
36
37export default setTextContent;

Callers 3

resetTextContentFunction · 0.85
setPropFunction · 0.85
setPropOnCustomElementFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected