Last active
December 3, 2021 15:34
-
-
Save renatoalencar/20b53a6a1b50ad32ec42203bbf12219d to your computer and use it in GitHub Desktop.
React fiber tree traversal
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
let root = $0._reactRootContainer._internalRoot | |
let node | |
let count | |
let map | |
node = root.current | |
count = 0 | |
map = new Map() | |
while (node) { | |
count++ | |
if (node.stateNode !== null) | |
map.set(node.stateNode, node) | |
if (node.child === null) { | |
while (node !== null && node.sibling === null) | |
node = node.return | |
node = node?.sibling | |
continue | |
} | |
node = node.child | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment