React Re-render Triggers: State, Parents, Props, Context

REACT INTERNALS - PART 4 What Actually Triggers a Re-render? In the previous parts, we saw: 1. Rendering recalculates UI 2. Reconciliation compares elements 3. Keys preserve identity Now the real question: When does React decide to render again? 🔥 The 4 Main Re-render Triggers 1️⃣ State Updates setCount(count + 1) When state changes, the component function runs again. Important detail: The component re-runs - not necessarily the entire DOM updating. Rendering ≠ DOM mutation. 2️⃣ Parent Re-renders If a parent component re-renders, its children re-render too. Unless they are memoized (React.memo) and their props are referentially stable. This is why component boundaries matter. 3️⃣ Props Reference Changes React compares props using shallow comparison. <Child config={{ theme: "dark" }} /> A new object is created on every render → new reference → child re-renders. Even if the values look identical. React compares references, not deep values. 4️⃣ Context Value Changes When a context value changes: All consuming components re-render. Even if they use only part of that value. Context widens the render scope. 🧠 Important Mental Model React re-renders when: 1. State changes 2. Parent renders 3. Props reference changes 4. Context updates React does not re-render when: 1. Variables change 2. You mutate objects silently 3. You update the DOM manually React responds to its own state system - not external mutations. 🎯 Why This Matters Performance issues usually aren’t caused by React. They’re caused by: 1. Poor state placement 2. Unstable references 3. Large render trees Understanding what triggers a re-render gives you control. And control is where performance architecture begins. #ReactJS #FrontendDevelopment #JavaScript #ReactInternals #SoftwareEngineering

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories