Skip to content

Instantly share code, notes, and snippets.

@CvX
Created June 17, 2015 16:51
Show Gist options
  • Save CvX/24bbc6ba410d0a68e547 to your computer and use it in GitHub Desktop.
Save CvX/24bbc6ba410d0a68e547 to your computer and use it in GitHub Desktop.
function findElement(options, instances) {
var React = require("React");
var ReactMount = require("ReactMount");
var ret = null;
if (!instances) instances = ReactMount._instancesByReactRootID;
for (n in instances) {
var instance = instances[n];
if (!instance) continue;
var element = instance._currentElement;
if (options.name) {
if (element && element.type && element.type.displayName == options.name) {
return instance.getPublicInstance().getDOMNode();
}
} else if (options.id) {
if (instance._rootNodeID == options.id) {
if (element.type.displayName) {
console.log(element.type.displayName);
} else {
console.log(element.type);
}
return instance;
}
}
if (typeof instance._stringText === 'string') continue;
if (instance._renderedComponent) {
ret = findElement(options, { a: instance._renderedComponent });
}
var children = instance._renderedChildren;
if (!ret && children) {
ret = findElement(options, children);
}
if (ret) return ret;
}
return null;
}
var a = findElement({ name: "MessengerSettingsMenu" });
var b = findElement({ id: ".0.1.$0.0.0.$1" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment