REACT INTERNALS - PART 10 How React Prioritizes Updates (Concurrent Rendering) In Part 9, we saw: • React batches multiple updates • Executes them in a single render Now the next question is: What if some updates are more important than others? 🔥 The Problem Not all updates should be treated equally. Example: • Typing in an input → urgent • Rendering a large list → heavy work If React processes both together: The UI can feel slow and unresponsive 🧩 Example function App() { const [input, setInput] = React.useState("") const [list, setList] = React.useState([]) const handleChange = (e) => { setInput(e.target.value) // urgent setList(generateBigList()) // heavy work } return <input onChange={handleChange} /> } ⚠️ Without Prioritization • Input update waits for heavy work • Typing feels slow • Poor user experience 🧠 Why This Happens React needs a way to handle updates with different importance 🧠 React’s Solution React introduces Concurrent Rendering to handle this It allows React to: • Prioritize important updates • Run less important work later 🔧 Using startTransition const [isPending, startTransition] = React.useTransition() const handleChange = (e) => { setInput(e.target.value) // high priority startTransition(() => { setList(generateBigList()) // low priority }) } 🔍 What Happens Now? • Input updates immediately • Heavy work runs later • UI stays responsive 🧠 What is Concurrent Rendering? Concurrent rendering means: React can pause, resume, or delay rendering work Instead of blocking the UI ⚠️ Important Clarification React is NOT truly parallel or multi-threaded • It does NOT run updates at the same time • It breaks work into small units • And schedules them intelligently 🎯 Key Insight React prioritizes urgent updates and runs less important work later 🔑 Final Takeaway Concurrent rendering keeps the UI responsive by scheduling updates based on priority Next: How React Fiber makes this possible internally #ReactJS #FrontendDevelopment #JavaScript #ReactInternals #SoftwareEngineering
React Prioritizes Updates with Concurrent Rendering
More Relevant Posts
-
𝗧𝗼𝗽 𝗥𝗲𝗮𝗰𝘁𝗝𝗦 𝗖𝗼𝗿𝗲 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 𝗘𝘃𝗲𝗿𝘆 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿 𝗦𝗵𝗼𝘂𝗹𝗱 𝗞𝗻𝗼𝘄 React is one of the most powerful libraries for building modern user interfaces. Understanding its core concepts is essential to building scalable, maintainable, and high-performance applications. Here are the most important React fundamentals every developer should master. 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 Components are the building blocks of a React application. Each component is reusable, independent, and responsible for a part of the UI. 𝗝𝗦𝗫 JSX allows you to write HTML-like syntax inside JavaScript. It makes UI code more readable and easier to maintain. 𝗣𝗿𝗼𝗽𝘀 Props are used to pass data from parent to child components. They are immutable and help maintain a predictable data flow. 𝗦𝘁𝗮𝘁𝗲 State is used to manage dynamic data within a component. When state updates, React automatically re-renders the UI. 𝗛𝗼𝗼𝗸𝘀 Hooks allow functional components to use state and lifecycle features. Common hooks include useState, useEffect, and useContext. 𝗩𝗶𝗿𝘁𝘂𝗮𝗹 𝗗𝗢𝗠 Virtual DOM is a lightweight copy of the real DOM. React updates only the changed elements, improving performance. 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗥𝗲𝗻𝗱𝗲𝗿𝗶𝗻𝗴 React allows rendering UI based on conditions, making applications dynamic and interactive. 𝗘𝘃𝗲𝗻𝘁 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴 React handles user interactions like clicks and inputs using synthetic events, ensuring cross-browser compatibility. 𝗨𝗻𝗶𝗱𝗶𝗿𝗲𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗗𝗮𝘁𝗮 𝗙𝗹𝗼𝘄 Data flows in one direction (parent to child), making applications easier to debug and maintain. 𝗦𝗶𝗺𝗽𝗹𝗲 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 Strong React applications are built by combining reusable components, efficient state management, and optimized rendering techniques. Mastering these fundamentals is the key to building scalable frontend systems. #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #UIEngineering #ReactHooks #VirtualDOM #Coding #LearningEveryday
To view or add a comment, sign in
-
🚀 Understanding Lists & Keys in React — Simplified! Rendering lists in React is easy… 👉 But doing it correctly is what most developers miss. 💡 What are Lists in React? Lists allow you to render multiple elements dynamically using arrays. const items = ["Apple", "Banana", "Mango"]; items.map((item) => <li>{item}</li>); 💡 What are Keys? 👉 Keys are unique identifiers for elements in a list items.map((item) => <li key={item}>{item}</li>); 👉 They help React track changes efficiently ⚙️ How it works When a list updates: 👉 React compares old vs new list 👉 Keys help identify: Added items Removed items Updated items 👉 This process is part of Reconciliation 🧠 Why Keys Matter Without keys: ❌ React may re-render entire list ❌ Performance issues ❌ Unexpected UI bugs With keys: ✅ Efficient updates ✅ Better performance ✅ Stable UI behavior 🔥 Best Practices (Most developers miss this!) ✅ Always use unique & stable keys ✅ Prefer IDs from data (best choice) ❌ Avoid using index as key (in dynamic lists) ⚠️ Common Mistake // ❌ Using index as key items.map((item, index) => <li key={index}>{item}</li>); 👉 Can break UI when items reorder 💬 Pro Insight Keys are not for styling or display— 👉 They are for React’s internal diffing algorithm 📌 Save this post & follow for more deep frontend insights! 📅 Day 11/100 #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #ReactInternals #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
𝐑𝐞𝐚𝐜𝐭 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐕𝐢𝐞𝐰 𝐓𝐫𝐚𝐩: How do you write an Error Boundary using functional components? 🚨🏴☠️ If your answer is, "I’ll just use a try/catch inside a useEffect," you might be costing yourself the offer. Here is a quick refresher on Error Boundaries and the production-level tip you need to ace this question. 🧠 𝐓𝐡𝐞 𝐂𝐨𝐫𝐞 𝐂𝐨𝐧𝐜𝐞𝐩𝐭 Since React 16, a single unhandled error in a component during rendering will unmount the entire component tree—resulting in the dreaded blank white screen. Error Boundaries act like a massive catch {} block for your UI. If a localized component (like a product review widget) crashes, the boundary catches it, prevents the rest of the page from unmounting, and displays a graceful fallback UI instead. 📌 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐓𝐢𝐩 Interviewers love asking how to build one in modern, functional React. The catch? You can't. Native React still requires a Class Component using componentDidCatch or static getDerivedStateFromError to build a boundary from scratch. There are no hook equivalents yet. 💻 𝐏𝐫𝐨𝐝𝐮𝐜𝐭𝐢𝐨𝐧 𝐀𝐩𝐩 𝐮𝐬𝐞 𝐜𝐚𝐬𝐞 If you want to show senior-level thinking, explain that while you can write a custom class wrapper, the industry standard for production apps is using Brian Vaughn’s react-error-boundary library. Why? It gives you two massive advantages: 1. 𝘾𝙡𝙚𝙖𝙣 𝙁𝙪𝙣𝙘𝙩𝙞𝙤𝙣𝙖𝙡 𝙒𝙧𝙖𝙥𝙥𝙚𝙧𝙨: You get a <ErrorBoundary> component that accepts a simple fallback UI and an onReset function to easily clear caches and let the user "try again." 2. 𝘾𝙖𝙩𝙘𝙝𝙞𝙣𝙜 𝙩𝙝𝙚 𝙪𝙣𝙘𝙖𝙩𝙘𝙝𝙖𝙗𝙡𝙚: Native error boundaries cannot catch errors inside async API calls or event handlers (like an onClick). The library provides a useErrorBoundary hook that allows you to manually push async errors into the boundary, triggering your fallback UI perfectly. Stop letting a single broken widget crash your entire application! #ReactJS #WebDevelopment #Frontend #SoftwareEngineering #TechInterviews #JavaScript
To view or add a comment, sign in
-
-
𝐑𝐞𝐚𝐜𝐭 𝐟𝐞𝐞𝐥𝐬 𝐟𝐚𝐬𝐭. 𝐁𝐮𝐭 𝐦𝐨𝐬𝐭 𝐝𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫𝐬 𝐝𝐨𝐧’𝐭 𝐤𝐧𝐨𝐰 𝐰𝐡𝐲. You update state. The UI updates instantly. Everything just… works. Until it doesn’t. Lists start behaving weirdly 🔁 Components re-render unexpectedly 🔄 Performance drops in larger apps 📉 Keys start causing subtle bugs 🔑 And suddenly, React doesn’t feel so “magical” anymore. New Substack article is live ✍️ “𝐑𝐞𝐚𝐜𝐭 𝐑𝐞𝐜𝐨𝐧𝐜𝐢𝐥𝐢𝐚𝐭𝐢𝐨𝐧 𝐄𝐱𝐩𝐥𝐚𝐢𝐧𝐞𝐝 𝐒𝐢𝐦𝐩𝐥𝐲” In this piece, I break down: 1️⃣ what reconciliation actually is (without jargon) 2️⃣ how React compares UI trees efficiently 3️⃣ why element types matter more than you think 4️⃣ how keys control performance and bugs 5️⃣ and how React reduces complex diffing to O(n) The biggest shift for me was this: React isn’t “updating the DOM.” It’s constantly asking: 👉 “What’s the smallest change I can make?” And everything clicks once you see that. 🔗 Read it here: https://lnkd.in/gpnZNtdy Curious — what’s one React concept that finally “clicked” for you recently? #FrontendEngineering #ReactJS #WebDevelopment #JavaScript #SoftwareEngineering #BuildInPublic
To view or add a comment, sign in
-
𝐇𝐨𝐰 𝐈 𝐑𝐞𝐝𝐮𝐜𝐞𝐝 𝐑𝐞𝐚𝐜𝐭 𝐑𝐞𝐧𝐝𝐞𝐫 𝐓𝐢𝐦𝐞 𝐛𝐲 𝟔𝟎% 🚀 Recently, I worked on a React application where the UI felt slow and unresponsive 😓 Pages were taking too long to update especially with large data sets So I decided to debug the issue 👇 🔍 Step 1 — Measured performance Used React DevTools Profiler Found multiple unnecessary re-renders ⚠️ Problem Every state change was re-rendering large components unnecessarily Fixes I applied 👇 ⚡ Used React.memo Prevented child components from re-rendering when props didn’t change 🧠 Applied useMemo Memoized expensive calculations to avoid recalculating on every render 🔁 Used useCallback Stopped functions from being recreated on every render 📦 Improved component structure Split large components into smaller ones Moved state closer to where it was needed 🔑 Fixed key usage in lists Replaced index keys with unique IDs 🚀 Result ✔ ~60% reduction in render time ✔ Smooth UI interactions ✔ Better user experience Key learning 💡 Performance issues are often not obvious They hide in unnecessary re-renders Tip for developers ⚠️ Don’t optimize blindly Measure → Identify → Fix Good developers make things work. Great developers make them fast. #ReactJS #FrontendDeveloper #WebDevelopment #JavaScript #Performance #ReactOptimization #SoftwareDeveloper #CodingInterview
To view or add a comment, sign in
-
-
Functional Components vs Class Components in React Most beginners think Components in React are just reusable pieces of UI. But in reality, React has 2 types of Components: * Functional Components * Class Components * Functional Component: const Welcome = () => { return <h1>Hello World</h1>; }; * Class Component: class Welcome extends React.Component { render() { return <h1>Hello World</h1>; } } At first, both may look similar. But the biggest difference comes when you want to: * Manage State * Run API calls * Handle component load/update/remove Functional Components use Hooks: *useState() *useEffect() Class Components use Lifecycle Methods: * componentDidMount() * componentDidUpdate() * componentWillUnmount() Simple mapping: * componentDidMount() → useEffect(() => {}, []) * componentDidUpdate() → useEffect(() => {}, [value]) * componentWillUnmount() → cleanup function inside useEffect Why most developers use Functional Components today: * Less code * Easier to read * Easier to manage * Supports Hooks * Modern React projects use them Class Components are still important because: * Old projects still use them * Interviews ask about them * They help you understand how useEffect works If you are learning React today: Learn Functional Components first. Then understand Class Components. Because understanding both makes you a better React developer. #react #reactjs #javascript #frontend #webdevelopment #useeffect #coding
To view or add a comment, sign in
-
-
💡 Understanding a subtle React concept: Hydration & “bailout” behavior One interesting nuance in React (especially with SSR frameworks like Next.js) is how hydration interacts with state updates. 👉 Hydration is the process where React makes server-rendered HTML interactive by attaching event listeners and syncing state on the client. When a page is server-rendered, the initial HTML is already in place. During hydration, React attaches event listeners and syncs the client state with that UI. Here’s the catch 👇 👉 If the client-side state matches what React expects, it may skip updating the DOM entirely. This is due to React’s internal optimization often referred to as a “bailout”. 🔍 Why this matters In cases like theme handling (dark/light mode): If the server renders a default UI (say light mode ☀️) And the client immediately initializes state to dark mode 🌙 React may still skip the DOM update if it doesn’t detect a meaningful state transition 👉 Result: UI can temporarily reflect the server version instead of the actual state. 🧠 Conceptual takeaway A more reliable pattern is: ✔️ Start with an SSR-safe default (consistent with server output) ✔️ Then update state after hydration (e.g., in a layout effect) This ensures React sees a real state change and updates the UI accordingly. 🙌 Why this is fascinating It highlights how deeply optimized React is — sometimes so optimized that understanding its internal behavior becomes essential for building predictable UI. Grateful to the developer community for continuously sharing such insights that go beyond surface-level coding. 🚀 Key idea In SSR apps, correctness isn’t just about what state you set — it’s also about when React observes the change. #ReactJS #NextJS #FrontendDevelopment #WebDevelopment #JavaScript #Learning
To view or add a comment, sign in
-
-
🚀 React Reconciliation — How React Actually Updates the UI Ever wondered… 👉 How React updates only what’s needed? 👉 Why it feels so fast? The answer is 👉 Reconciliation 💡 What is Reconciliation? Reconciliation is the process React uses to: 👉 Compare old Virtual DOM vs new Virtual DOM 👉 Update only the changed parts in the Real DOM ⚙️ How it works (Step-by-step) 1️⃣ State/props change triggers re-render 2️⃣ React creates a new Virtual DOM tree 3️⃣ Compares it with previous tree (Diffing) 4️⃣ Finds minimal changes 5️⃣ Updates only those parts in Real DOM 🧠 Key Concept → Diffing Algorithm React uses a heuristic diffing algorithm: 👉 Instead of comparing everything 👉 It makes smart assumptions to optimize updates 🔥 Important Rules React Follows ✔ Different element types → full re-render ✔ Same type → update only changed attributes ✔ Keys help identify list items 🧩 Example // Before <ul> <li>A</li> <li>B</li> </ul> // After <ul> <li>A</li> <li>C</li> </ul> 👉 React updates only B → C 👉 Not the entire list ⚠️ Why Keys Are Critical Without keys: ❌ React may re-render entire list ❌ UI bugs may occur With keys: ✅ Efficient updates ✅ Stable UI 🔥 Performance Insight Reconciliation makes React fast… 👉 But only if you write optimized code Bad patterns: ❌ Missing keys ❌ Unstable references ❌ Unnecessary re-renders 💬 Pro Insight (Senior-Level Thinking) 👉 React doesn’t update the DOM blindly 👉 It calculates the minimum work required 📌 Save this post & follow for more deep frontend insights! 📅 Day 22/100 #ReactJS #FrontendDevelopment #JavaScript #ReactInternals #PerformanceOptimization #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🚀 Controlled vs Uncontrolled Components in React — Real-World Perspective Most developers learn: 👉 Controlled = React state 👉 Uncontrolled = DOM refs But in real applications… 👉 The choice impacts performance, scalability, and maintainability. 💡 Quick Recap 🔹 Controlled Components: Managed by React state Re-render on every input change 🔹 Uncontrolled Components: Managed by the DOM Accessed via refs ⚙️ The Real Problem In large forms: ❌ Controlled inputs → Too many re-renders ❌ Uncontrolled inputs → Hard to validate & manage 👉 So which one should you use? 🧠 Real-world Decision Rule 👉 Use Controlled when: ✔ You need validation ✔ UI depends on input ✔ Dynamic form logic exists 👉 Use Uncontrolled when: ✔ Performance is critical ✔ Minimal validation needed ✔ Simple forms 🔥 Performance Insight Controlled input: <input value={name} onChange={(e) => setName(e.target.value)} /> 👉 Re-renders on every keystroke Uncontrolled input: <input ref={inputRef} /> 👉 No re-render → better performance ⚠️ Advanced Problem (Most devs miss this) 👉 Large forms with 20+ fields Controlled approach: ❌ Can slow down typing 👉 Solution: ✔ Hybrid approach ✔ Use libraries (React Hook Form) 🧩 Industry Pattern Modern apps often use: 👉 Controlled logic + Uncontrolled inputs internally Example: ✔ React Hook Form ✔ Formik (optimized patterns) 🔥 Best Practices ✅ Use controlled for logic-heavy forms ✅ Use uncontrolled for performance-critical inputs ✅ Consider form libraries for scalability ❌ Don’t blindly use controlled everywhere 💬 Pro Insight (Senior Thinking) 👉 This is not about “which is better” 👉 It’s about choosing the right tool for the problem 📌 Save this post & follow for more deep frontend insights! 📅 Day 17/100 #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #PerformanceOptimization #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Nice breakdown of Concurrent Rendering 👍 In similar scenarios, useDeferredValue can also be useful when the heavy computation depends on a value (like input). Instead of deferring the update itself, it defers the value used for rendering — helping keep the UI responsive without explicitly managing transitions.