pomber / didact

A DIY guide to build your own React
https://pomb.us/build-your-own-react/
6.29k stars 531 forks source link

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

Open Huangqye opened 2 years ago

Huangqye commented 2 years ago

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.

shadowvzs commented 2 years ago

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

Huangqye commented 2 years ago

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?

Akarinx commented 1 year ago

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

electroluxcode commented 1 year ago

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