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

Function getClosestInstanceFromNode

code/communication/public/app.js:2477–2499  ·  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

2475 * ReactDOMTextComponent instance ancestor.
2476 */
2477function getClosestInstanceFromNode(node) {
2478 if (node[internalInstanceKey]) {
2479 return node[internalInstanceKey];
2480 }
2481
2482 while (!node[internalInstanceKey]) {
2483 if (node.parentNode) {
2484 node = node.parentNode;
2485 } else {
2486 // Top of the tree. This node must not be part of a React tree (or is
2487 // unmounted, potentially).
2488 return null;
2489 }
2490 }
2491
2492 var inst = node[internalInstanceKey];
2493 if (inst.tag === HostComponent || inst.tag === HostText) {
2494 // In Fiber, this will always be the deepest root.
2495 return inst;
2496 }
2497
2498 return null;
2499}
2500
2501/**
2502 * 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