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

Function getClosestInstanceFromNode

code/third-party/public/app.js:1675–1697  ·  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

1673 * ReactDOMTextComponent instance ancestor.
1674 */
1675function getClosestInstanceFromNode(node) {
1676 if (node[internalInstanceKey]) {
1677 return node[internalInstanceKey];
1678 }
1679
1680 while (!node[internalInstanceKey]) {
1681 if (node.parentNode) {
1682 node = node.parentNode;
1683 } else {
1684 // Top of the tree. This node must not be part of a React tree (or is
1685 // unmounted, potentially).
1686 return null;
1687 }
1688 }
1689
1690 var inst = node[internalInstanceKey];
1691 if (inst.tag === HostComponent || inst.tag === HostText) {
1692 // In Fiber, this will always be the deepest root.
1693 return inst;
1694 }
1695
1696 return null;
1697}
1698
1699/**
1700 * 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