Skip to content

Instantly share code, notes, and snippets.

@unarist
Last active March 9, 2018 16:18
Show Gist options
  • Save unarist/a0a4bd36ac613b5cbbd9cfaccfba32b2 to your computer and use it in GitHub Desktop.
Save unarist/a0a4bd36ac613b5cbbd9cfaccfba32b2 to your computer and use it in GitHub Desktop.
Capture rendered .status__wrapper node by hooking Status.prototype.render
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