A component re-renders if and only if one of four events occurs:
1
Local State Update: The component calls its own useState or useReducer updater function.
2
Parent Component Re-render: The parent component re-renders (triggering an automatic downward cascade).
3
Context Consumption: A React Context that the component subscribes to via useContext changes its value.
4
Hook Update: A custom hook called inside the component triggers a state update.
3. Re-rendering vs DOM Updating
Engineers often panic when they see re-renders in DevTools, confusing a Virtual DOM re-render with a real DOM mutation.
Re-rendering: Executing the component function in memory to produce a new Virtual DOM tree. In modern JavaScript engines, this calculation is measured in microseconds and is extremely cheap.
Reconciliation & DOM Painting: Modifying physical DOM nodes on screen. React's diffing engine ensures that even if a component re-renders, the real browser DOM is only touched if the calculated output actually changed!
Re-renders only become a performance problem when: