The Golden Rule 🏠 Positioning ( top , left , etc.) 👉 Moves relative to the PARENT 🚶 Translate ( translate-x , translate-y ) 👉 Moves relative to ITSELF That’s it. If you remember only this, you’ll never confuse them again. 🎯 Imagine This Real-Life Story Think of a room (parent) and a table (element) . 1️⃣ left-1/2 → Parent Based You tell someone: “Put the table so its left edge is at 50% of the room.” The room decides the position. Room Width = 1000 px 50% = 500 px Table 's left edge is placed at 500px So positioning = 📏 Room measurement 2️⃣ translate-x-1/2 → Self Based Now you say: “Move the table forward by half of its own width.” The table measures itself. Table Width = 200px 50 % = 100px It moves 100px So translate = 📦 Self measurement 🔥 Ultimate Memory Formula Positioning → Parent controls me Translate → I control myself 💡 Why Centering Needs Both When you do: left - 1 / 2 You move the left edge to center. But the e...
in case of useref no need to deal with vdom directly real dom of browser is updated Venice That's a fantastic observation, and you're touching on the core power of useRef . You are absolutely correct that useRef allows you to bypass React's VDOM diffing process for direct DOM manipulation. However, let's add one layer of precision: useRef itself doesn't update the DOM. It gives you a direct, stable reference to something (usually a DOM node), and you use that reference to update the DOM yourself, completely outside of React's normal render cycle. Let's contrast the two flows. The useState Flow (The "Official" React Way) This is the "ask for permission" model. Trigger: You call setCount() . Render: React schedules a re-render. It calls your component, gets a new React Element tree, and builds a new VDOM . Reconciliation (Diffing): React compares the new VDOM to the old...