Skip to content

Instantly share code, notes, and snippets.

@renatoalencar
Last active December 3, 2021 15:34
Show Gist options
  • Save renatoalencar/20b53a6a1b50ad32ec42203bbf12219d to your computer and use it in GitHub Desktop.
Save renatoalencar/20b53a6a1b50ad32ec42203bbf12219d to your computer and use it in GitHub Desktop.
React fiber tree traversal
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