pomber / didact

A DIY guide to build your own React

Home Page:https://pomb.us/build-your-own-react/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Huangqye opened this issue · 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.

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

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?

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

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