Nishchaya Narula’s Post

🟨 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗗𝗮𝘆 𝟲𝟮: 𝗪𝗵𝘆 𝗗𝗢𝗠 𝗨𝗽𝗱𝗮𝘁𝗲𝘀 𝗔𝗿𝗲 𝗮 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 (𝗔𝗻𝗱 𝗛𝗼𝘄 𝗥𝗲𝗮𝗰𝘁 𝗧𝗵𝗶𝗻𝗸𝘀 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁𝗹𝘆) Updating UI looks simple… until it isn’t. 🔹 𝗛𝗼𝘄 𝗨𝗜 𝗨𝗽𝗱𝗮𝘁𝗲𝘀 𝗪𝗼𝗿𝗸 (𝗪𝗶𝘁𝗵𝗼𝘂𝘁 𝗥𝗲𝗮𝗰𝘁) • We directly update the DOM • We decide what to change and how Example: document.getElementById("title").innerText = "Hello" 🔹 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 • DOM operations are relatively expensive • You must track what changed manually • Easy to make mistakes • Becomes complex as UI grows 🔹 𝗪𝗵𝗮𝘁 𝗺𝗮𝗸𝗲𝘀 𝗶𝘁 𝗵𝗮𝗿𝗱 • UI = multiple states + frequent updates • Small changes can affect many elements • Manual DOM handling doesn’t scale well 🔹 𝗪𝗵𝗮𝘁 𝗥𝗲𝗮𝗰𝘁 𝗖𝗵𝗮𝗻𝗴𝗲𝘀 • You don’t update DOM directly • You describe what UI should look like • React figures out the most efficient way to update 🔹 𝗞𝗲𝘆 𝗜𝗱𝗲𝗮 • Shift from “How to update UI” • To “What should UI look like” 🔹 𝗧𝗵𝗲 𝗠𝗶𝘀𝘀𝗶𝗻𝗴 𝗣𝗶𝗲𝗰𝗲 👉 But how does React know what actually changed? 👉 This is where Virtual DOM comes in 👉 React creates a representation of UI and compares it before updating the real DOM 🔹 𝗠𝗼𝘀𝘁 𝗜𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝗜𝗻𝘀𝗶𝗴𝗵𝘁 • Problem is NOT creating UI • Problem is updating it efficiently 💬 GitHub link in comments. #JavaScript #React #Frontend #Day62 #100DaysOfCode

To view or add a comment, sign in

Explore content categories