React Rendering Masterclass
How React Thinks: The Secrets of Fiber, Reconciliation, and Rendering
Many programmers think that React "just re-renders the component when state changes". But in reality, React has its own "virtual mind" β a complex system that determines:
All of this is possible thanks to the Fiber architecture.
React never directly changes the real DOM. Instead, it creates a lightweight copy of it (Virtual DOM) in memory.
function App() {
return <h1>Hello, Aram!</h1>;
}
React doesn't paint this directly to the screen. First, it creates a Virtual DOM tree:
App
βββ h1
βββ "Hello, Aram!"
When state changes, React creates a new Virtual DOM, compares the old and new versions β π this step is called reconciliation. Then React only changes the differences in the real DOM, whatever has changed.
Starting from React 16 (Fiber architecture), rendering was completely rewritten. Fiber allows React to interrupt rendering, leave it incomplete and then resume it.
Each component is now represented as a "Fiber node" β an object that holds:
{
type: ComponentFunction,
pendingProps: {},
memoizedState: {},
return: ParentFiber,
child: ChildFiber,
sibling: SiblingFiber
}
This tree allows React to understand:
React performs rendering in two phases π
Render Phase β Commit Phase β Browser Paint
This approach is what enables Concurrent Rendering in React 18. React can say: "Wait, I haven't finished rendering this component now, but the other one needs to be shown more urgently."
React never re-renders on every state update. React "batches" them together β in one render.
setCount(c => c + 1);
setCount(c => c + 1);
π React sees this as one operation β not two renders. As a result, performance significantly improves.
In Concurrent Mode, React also uses a scheduler that determines:
Open React DevTools β Profiler. There you can see:
function Counter() {
const [count, setCount] = useState(0);
console.log('render');
return (
<button onClick={() => setCount(c => c + 1)}>
{count}
</button>
);
}
In the Profiler, you'll notice: React only re-renders the component whose state has changed β not the entire tree.
React is not just a UI library. It's a complete rendering engine with its own scheduler, priority system and memory management. Thanks to Fiber, React can now be: