didact icon indicating copy to clipboard operation
didact copied to clipboard

I learned from 'Build Your Own React' and encountered problems in building Fiber

Open Huangqye opened this issue 3 years ago • 4 comments

in step 4 Fiber, prevSibling.sibling = newFiber;, fiber is the argument and prevSibling is the variable inside the function. How does the sibling come into fiber? Thank you.

Huangqye avatar Jul 11 '22 08:07 Huangqye

there is a while loop, inside that while loop was setted far as i see :)

shadowvzs avatar Jul 11 '22 08:07 shadowvzs

there is a while loop, inside that while loop was setted far as i see :)

Thank you for your reply. I really want to know how fiber can bind the sibling?

Huangqye avatar Jul 11 '22 08:07 Huangqye

first loop: fiber.child = newFiber, prevFiber = newFiber . fiber -> child -> newFiber; next loop: prevFiber.sibling = nextNewFiber , fiber -> child -> newFiber -> sibling ->nextNewFiber

Akarinx avatar Jan 11 '23 16:01 Akarinx

To be honest, I don't think the author's approach is easy to understand. My treatment of sibling is if (i == 0) { fiber.children = newFiber } else { fiber.sibling = newFiber } Specific can refer to:https://codepen.io/yilaikesi/pen/xxaYqLQ

electroluxcode avatar Mar 13 '23 02:03 electroluxcode