Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getReactInstancesForNode (node, { firstOnly } = {}) {
- const key = Object.keys(node).find(key => key.startsWith("__reactInternalInstance$"));
- let inst = node[key];
- const results = [];
- while (inst) {
- if (typeof inst.elementType === "function") {
- const result = {
- type: inst.elementType,
- };
- if (inst.stateNode) {
- // NOTE: stateless components have no instance
- result.instance = inst.stateNode;
- }
- if (inst.memoizedProps) {
- result.props = inst.memoizedProps;
- }
- if (inst.memoizedState) {
- // NOTE: stateless components have no instance
- result.state = inst.memoizedState;
- }
- if (firstOnly) {
- return result;
- }
- results.push(result);
- }
- inst = inst.return;
- }
- return results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement