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

Function getClosestInstanceFromNode

code/styling/public/app.js:2442–2464  ·  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

2440 * ReactDOMTextComponent instance ancestor.
2441 */
2442function getClosestInstanceFromNode(node) {
2443 if (node[internalInstanceKey]) {
2444 return node[internalInstanceKey];
2445 }
2446
2447 while (!node[internalInstanceKey]) {
2448 if (node.parentNode) {
2449 node = node.parentNode;
2450 } else {
2451 // Top of the tree. This node must not be part of a React tree (or is
2452 // unmounted, potentially).
2453 return null;
2454 }
2455 }
2456
2457 var inst = node[internalInstanceKey];
2458 if (inst.tag === HostComponent || inst.tag === HostText) {
2459 // In Fiber, this will always be the deepest root.
2460 return inst;
2461 }
2462
2463 return null;
2464}
2465
2466/**
2467 * 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