MCPcopy Create free account
hub / github.com/Lobos/react-ui / getNodeFromInstance

Function getNodeFromInstance

docs/lib/react.js:7410–7434  ·  view source on GitHub ↗

* Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding * DOM node.

(inst)

Source from the content-addressed store, hash-verified

7408 * DOM node.
7409 */
7410function getNodeFromInstance(inst) {
7411 // Without this first invariant, passing a non-DOM-component triggers the next
7412 // invariant for a missing parent, which is super confusing.
7413 !(inst._nativeNode !== undefined) ? "development" !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : invariant(false) : void 0;
7414
7415 if (inst._nativeNode) {
7416 return inst._nativeNode;
7417 }
7418
7419 // Walk up the tree until we find an ancestor whose DOM node we have cached.
7420 var parents = [];
7421 while (!inst._nativeNode) {
7422 parents.push(inst);
7423 !inst._nativeParent ? "development" !== 'production' ? invariant(false, 'React DOM tree root should always have a node reference.') : invariant(false) : void 0;
7424 inst = inst._nativeParent;
7425 }
7426
7427 // Now parents contains each ancestor that does *not* have a cached native
7428 // node, and `inst` is the deepest ancestor that does.
7429 for (; parents.length; inst = parents.pop()) {
7430 precacheChildNodes(inst, inst._nativeNode);
7431 }
7432
7433 return inst._nativeNode;
7434}
7435
7436var ReactDOMComponentTree = {
7437 getClosestInstanceFromNode: getClosestInstanceFromNode,

Callers

nothing calls this directly

Calls 2

precacheChildNodesFunction · 0.85
invariantFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…