Skip to main content

Posts

position vs translate

  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...
Recent posts

Use Ref

  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...

Virtual DOM vs Real DOM

  okay it mean in case of useState there is initial virtual dom when state is updated a new instance of vdom is created and both vdom are compared and only minimal sort of change required in particular node of real dom is done. Venice Yes, you've got the core idea exactly right, but with one crucial clarification that's a common point of confusion. Let's refine your statement slightly for technical precision. Your statement:  "in case of  useState  there is initial virtual dom when state is updated a new instance of vdom is created and both vdom are compared and only minimal sort of change required in particular node of real dom is done." The Refined Version:  When  useState  updates, a  new React Element tree is created , which is then used to generate a  new Virtual DOM (VDOM) representation . This new VDOM is then compared ( diffed ) against the VDOM from the previous render. React calculates the minimal set of changes and applies them to ...