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

Function getClosestInstanceFromNode

code/new-context-api/public/app.js:1803–1825  ·  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

1801 * ReactDOMTextComponent instance ancestor.
1802 */
1803function getClosestInstanceFromNode(node) {
1804 if (node[internalInstanceKey]) {
1805 return node[internalInstanceKey];
1806 }
1807
1808 while (!node[internalInstanceKey]) {
1809 if (node.parentNode) {
1810 node = node.parentNode;
1811 } else {
1812 // Top of the tree. This node must not be part of a React tree (or is
1813 // unmounted, potentially).
1814 return null;
1815 }
1816 }
1817
1818 var inst = node[internalInstanceKey];
1819 if (inst.tag === HostComponent || inst.tag === HostText) {
1820 // In Fiber, this will always be the deepest root.
1821 return inst;
1822 }
1823
1824 return null;
1825}
1826
1827/**
1828 * 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