Last active
March 9, 2018 16:18
-
-
Save unarist/a0a4bd36ac613b5cbbd9cfaccfba32b2 to your computer and use it in GitHub Desktop.
Capture rendered .status__wrapper node by hooking Status.prototype.render
This file contains hidden or 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
node = Object.entries(document.querySelector('.status__wrapper')).find(prop=>prop[0].startsWith('__reactInternalInstance'))[1]; | |
// Status component has "status" prop | |
while (node.memoizedProps.status === undefined) { | |
node = node.return; | |
} | |
Status = node.type; | |
originalMethod = Status.prototype.render; | |
Status.prototype.render = function(){ | |
// obtain rendered tree | |
const ret = originalMethod.call(this); | |
// ignore <div>account content</div> | |
if (ret.type !== 'div') { | |
// ret == <HotKeys>, ret.props.children == <div> | |
// then, setRef=console.log for <div> | |
ret.props.children.ref = console.log; | |
} | |
return ret; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment