通过dom获取react节点
window.FindReact = function(dom) {let key = Object.keys(dom).find(key=>key.startsWith("__reactInternalInstance$"));
let internalInstance = dom[key];
if (internalInstance == null) return null;
if (internalInstance.return) { // react 16+
return internalInstance._debugOwner
? internalInstance._debugOwner.stateNode
: internalInstance.return.stateNode;
} else { // react <16
return internalInstance._currentElement._owner._instance;
}
}
出处:https://stackoverflow.com/questions/47166101/is-it-possible-to-retrieve-a-components-instance-from-a-react-fiber/58968770#58968770
以上是 通过dom获取react节点 的全部内容, 来源链接: utcz.com/z/381887.html