Created
March 13, 2018 12:32
-
-
Save JosePedroDias/8ebfed3d694a670294247bdd5dbf93d2 to your computer and use it in GitHub Desktop.
expose react hook internals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var noop = function() {}; | |
var h = __REACT_DEVTOOLS_GLOBAL_HOOK__; | |
var helpers = h.helpers[ Object.keys(h.helpers)[0] ]; | |
window.helpers = helpers; | |
/*helpers.walkTree( | |
noop, | |
function(r) { | |
window.root = r; | |
} | |
);*/ | |
window.findInstancesByName = function(name) { | |
var i = []; | |
helpers.walkTree( | |
function(n) { | |
const t = n._currentElement.type; | |
if (typeof t === 'function' && name === t.name) { | |
i.push(n._instance); | |
} | |
}, | |
noop | |
); | |
return i; | |
} | |
window.findInstancesByTag = function(tagName) { | |
var i = []; | |
helpers.walkTree( | |
function(n) { | |
if (n._tag === tagName) { | |
i.push(n._currentElement._owner._instance); | |
} | |
}, | |
noop | |
); | |
return i; | |
}; | |
window.findInstancesByClass = function(className) { | |
var i = []; | |
helpers.walkTree( | |
function(n) { | |
if (n._hostNode && n._hostNode.className && n._hostNode.className === className) { | |
i.push(n._currentElement._owner._instance); | |
} | |
}, | |
noop | |
); | |
return i; | |
}; | |
window.findInstanceByName = function(name) { | |
return window.findInstancesByName(name)[0]; | |
}; | |
window.findInstanceByTag = function(tagName) { | |
return window.findInstancesByTag(tagName)[0]; | |
}; | |
window.findInstanceByClass = function(className) { | |
return window.findInstancesByClass(className)[0]; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment