MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / getClosestInstanceFromNode

Function getClosestInstanceFromNode

code/composition/public/app.js:2580–2602  ·  view source on GitHub ↗

* Given a DOM node, return the closest ReactDOMComponent or * ReactDOMTextComponent instance ancestor.

(node)

Source from the content-addressed store, hash-verified

2578 * ReactDOMTextComponent instance ancestor.
2579 */
2580function getClosestInstanceFromNode(node) {
2581 if (node[internalInstanceKey]) {
2582 return node[internalInstanceKey];
2583 }
2584
2585 while (!node[internalInstanceKey]) {
2586 if (node.parentNode) {
2587 node = node.parentNode;
2588 } else {
2589 // Top of the tree. This node must not be part of a React tree (or is
2590 // unmounted, potentially).
2591 return null;
2592 }
2593 }
2594
2595 var inst = node[internalInstanceKey];
2596 if (inst.tag === HostComponent || inst.tag === HostText) {
2597 // In Fiber, this will always be the deepest root.
2598 return inst;
2599 }
2600
2601 return null;
2602}
2603
2604/**
2605 * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent

Callers 3

app.jsFile · 0.70
handleTopLevelFunction · 0.70
dispatchEventFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected