4 ms·
Out of curiosity, what about renders confuses you? I can try to summarize: - React stores an internal tree of bookkeeping objects ("fibers") that store info o
by acemarke 7y ago
Out of curiosity, what about renders confuses you?
I can try to summarize:
- React stores an internal tree of bookkeeping objects ("fibers") that store info on what component is being rendered at each location in the tree
- Any state update function (class component `setState()`, `useState` setters, `useReducer` dispatch) queue a re-render pass, and mark this component as needing an update
- During a re-render pass, React walks that fiber tree to find components that need to render, either because they're marked as dirty, or because the parent re-rendered. For function components, React calls `funcComp(fiber.props)`. For class components, it attaches `instance.props = fiber.props`, and then calls `instance.render()`
- Class component lifecycles and function component lifecycles are called at appropriate points during that render pass
Hmm. Re-reading, are you asking how to determine what _causes_ a given render pass? That one's more opaque. However, the new React DevTools 4.0 will at least tell you why each component re-rendered during a specific pass.
- swyx 7y agoi believe they dont even want people fixated on when and why things rerender. write your code right (with effects and suspense boundaries in the right places) and let react figure it out. not sure if they'll succeed in making people not care about optimizing for number of renders vs overall speed tbh. we're so used to one way of thinking about perf.