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

Function getClosestInstanceFromNode

code/redux/public/app.js:2693–2715  ·  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

2691 * ReactDOMTextComponent instance ancestor.
2692 */
2693function getClosestInstanceFromNode(node) {
2694 if (node[internalInstanceKey]) {
2695 return node[internalInstanceKey];
2696 }
2697
2698 while (!node[internalInstanceKey]) {
2699 if (node.parentNode) {
2700 node = node.parentNode;
2701 } else {
2702 // Top of the tree. This node must not be part of a React tree (or is
2703 // unmounted, potentially).
2704 return null;
2705 }
2706 }
2707
2708 var inst = node[internalInstanceKey];
2709 if (inst.tag === HostComponent || inst.tag === HostText) {
2710 // In Fiber, this will always be the deepest root.
2711 return inst;
2712 }
2713
2714 return null;
2715}
2716
2717/**
2718 * 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