Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function getReactInstancesForNode (node, { firstOnly } = {}) {
  2. const key = Object.keys(node).find(key => key.startsWith("__reactInternalInstance$"));
  3. let inst = node[key];
  4. const results = [];
  5. while (inst) {
  6. if (typeof inst.elementType === "function") {
  7. const result = {
  8. type: inst.elementType,
  9. };
  10. if (inst.stateNode) {
  11. // NOTE: stateless components have no instance
  12. result.instance = inst.stateNode;
  13. }
  14. if (inst.memoizedProps) {
  15. result.props = inst.memoizedProps;
  16. }
  17. if (inst.memoizedState) {
  18. // NOTE: stateless components have no instance
  19. result.state = inst.memoizedState;
  20. }
  21. if (firstOnly) {
  22. return result;
  23. }
  24. results.push(result);
  25. }
  26. inst = inst.return;
  27. }
  28. return results;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement