🚀 Day 22 – React Portals (Break Out of the DOM Tree) As your UI grows, you may face layout issues: ⚠️ Modals hidden behind elements ⚠️ Tooltips getting clipped ⚠️ z-index not working as expected The problem is not CSS… 👉 It’s DOM hierarchy 🛒 Simple Analogy Imagine a building 🏢 🔴 Without Portal You’re stuck inside nested rooms 👉 Your message stays hidden inside 👉 No one outside can see it 😓 🟢 With Portal You use an emergency exit 🚪 👉 Jump outside the building 👉 Now everyone can see your message 👉 That’s React Portal: Render outside parent hierarchy 🧠 Why Portals Matter Without Portals: • Content gets clipped • z-index issues • Poor UI layering With Portals: • Clean overlays • Proper layering • Better UX 💻 1. Without Portal (Problem) function App() { return ( <div style={{ overflow: "hidden" }}> <Modal /> {/* ❌ Might get clipped */} </div> ); } 💻 2. With Portal (Solution) import ReactDOM from "react-dom"; function Modal({ children }) { return ReactDOM.createPortal( <div className="modal">{children}</div>, document.getElementById("modal-root") ); } ✅ Renders outside parent ✅ No clipping issues 💻 3. HTML Setup <div id="root"></div> <div id="modal-root"></div> ⚡ How It Works 👉 Component stays in React tree 👉 But renders in different DOM node 📌 Key Concepts ✔ createPortal(child, container) ✔ Breaks out of parent DOM hierarchy ✔ Keeps React logic intact 🧠 Common Use Cases • Modals • Tooltips • Dropdowns • Notifications ⚠️ Important Note 👉 Events still bubble up through React tree 👉 Even if DOM position is different 💬 Developer Question Where do you use portals the most? 1️⃣ Modals 2️⃣ Tooltips 3️⃣ Dropdowns 4️⃣ Notifications #React #FrontendDevelopment #JavaScript #WebDevelopment #ReactJS #UIUX #CodingJourney 🚀
React Portals: Breaking Out of DOM Hierarchy
More Relevant Posts
-
"The Unified Search Engine for the Modern Developer’s Icon Workflow." https://svgiconsstock.com/ In the fast-paced world of web development, efficiency is the difference between shipping on time and falling behind. SVGIconsStock was born out of a simple frustration: the endless context-switching between different icon libraries, CDNs, and documentation pages. We’ve built a centralized discovery experience that bridges the gap between designers and developers. SVGIconsStock isn't just another asset gallery; it’s a high-performance utility built with Next.js that allows you to search, filter, and preview icons from multiple open-source libraries within a single, consistent interface. Whether you are looking for the perfect SVG for a landing page or managing a custom internal library for a design system, SVGIconsStock provides the tools to evaluate and integrate assets instantly. With our "Copy-to-Code" snippets and modular architecture, we remove the friction from frontend development, letting you focus on building great products rather than hunting for assets. Key Features & Capabilities Unified Discovery: One search bar to rule them all. Access thousands of icons across various popular libraries without leaving the platform. Developer-First Workflow: Get library-specific usage snippets (React, Vue, SVG, or Tailwind) for immediate implementation. Next.js Powered Speed: Experience lightning-fast filtering and instant previews thanks to a modern, modular component architecture. Custom Asset Management: A dedicated admin workflow for uploading, organizing, and tagging custom SVG assets for your specific projects. Designer-Friendly Interface: A clean, responsive UI that makes asset evaluation simple for both technical and creative team members. #SVGIconsStock #WebDev #UIUX #NextJS #Frontend #DesignSystem #SVGIconsStock #SVG #WebDevelopment #DeveloperTools #ReactJS #UIUXDesign #OpenSource #Productivity #NextJS #FrontendWorkflow
To view or add a comment, sign in
-
-
"The Unified Search Engine for the Modern Developer’s Icon Workflow." https://svgiconsstock.com/ In the fast-paced world of web development, efficiency is the difference between shipping on time and falling behind. SVGIconsStock was born out of a simple frustration: the endless context-switching between different icon libraries, CDNs, and documentation pages. We’ve built a centralized discovery experience that bridges the gap between designers and developers. SVGIconsStock isn't just another asset gallery; it’s a high-performance utility built with Next.js that allows you to search, filter, and preview icons from multiple open-source libraries within a single, consistent interface. Whether you are looking for the perfect SVG for a landing page or managing a custom internal library for a design system, SVGIconsStock provides the tools to evaluate and integrate assets instantly. With our "Copy-to-Code" snippets and modular architecture, we remove the friction from frontend development, letting you focus on building great products rather than hunting for assets. Key Features & Capabilities Unified Discovery: One search bar to rule them all. Access thousands of icons across various popular libraries without leaving the platform. Developer-First Workflow: Get library-specific usage snippets (React, Vue, SVG, or Tailwind) for immediate implementation. Next.js Powered Speed: Experience lightning-fast filtering and instant previews thanks to a modern, modular component architecture. Custom Asset Management: A dedicated admin workflow for uploading, organizing, and tagging custom SVG assets for your specific projects. Designer-Friendly Interface: A clean, responsive UI that makes asset evaluation simple for both technical and creative team members. #SVGIconsStock #WebDev #UIUX #NextJS #Frontend #DesignSystem #SVGIconsStock #SVG #WebDevelopment #DeveloperTools #ReactJS #UIUXDesign #OpenSource #Productivity #NextJS #FrontendWorkflow
To view or add a comment, sign in
-
-
"The Unified Search Engine for the Modern Developer’s Icon Workflow." https://svgiconsstock.com/ In the fast-paced world of web development, efficiency is the difference between shipping on time and falling behind. SVGIconsStock was born out of a simple frustration: the endless context-switching between different icon libraries, CDNs, and documentation pages. We’ve built a centralized discovery experience that bridges the gap between designers and developers. SVGIconsStock isn't just another asset gallery; it’s a high-performance utility built with Next.js that allows you to search, filter, and preview icons from multiple open-source libraries within a single, consistent interface. Whether you are looking for the perfect SVG for a landing page or managing a custom internal library for a design system, SVGIconsStock provides the tools to evaluate and integrate assets instantly. With our "Copy-to-Code" snippets and modular architecture, we remove the friction from frontend development, letting you focus on building great products rather than hunting for assets. Key Features & Capabilities Unified Discovery: One search bar to rule them all. Access thousands of icons across various popular libraries without leaving the platform. Developer-First Workflow: Get library-specific usage snippets (React, Vue, SVG, or Tailwind) for immediate implementation. Next.js Powered Speed: Experience lightning-fast filtering and instant previews thanks to a modern, modular component architecture. Custom Asset Management: A dedicated admin workflow for uploading, organizing, and tagging custom SVG assets for your specific projects. Designer-Friendly Interface: A clean, responsive UI that makes asset evaluation simple for both technical and creative team members. #SVGIconsStock #WebDev #UIUX #NextJS #Frontend #DesignSystem #SVGIconsStock #SVG #WebDevelopment #DeveloperTools #ReactJS #UIUXDesign #OpenSource #Productivity #NextJS #FrontendWorkflow
To view or add a comment, sign in
-
-
"The Unified Search Engine for the Modern Developer’s Icon Workflow." https://svgiconsstock.com/ In the fast-paced world of web development, efficiency is the difference between shipping on time and falling behind. SVGIconsStock was born out of a simple frustration: the endless context-switching between different icon libraries, CDNs, and documentation pages. We’ve built a centralized discovery experience that bridges the gap between designers and developers. SVGIconsStock isn't just another asset gallery; it’s a high-performance utility built with Next.js that allows you to search, filter, and preview icons from multiple open-source libraries within a single, consistent interface. Whether you are looking for the perfect SVG for a landing page or managing a custom internal library for a design system, SVGIconsStock provides the tools to evaluate and integrate assets instantly. With our "Copy-to-Code" snippets and modular architecture, we remove the friction from frontend development, letting you focus on building great products rather than hunting for assets. Key Features & Capabilities Unified Discovery: One search bar to rule them all. Access thousands of icons across various popular libraries without leaving the platform. Developer-First Workflow: Get library-specific usage snippets (React, Vue, SVG, or Tailwind) for immediate implementation. Next.js Powered Speed: Experience lightning-fast filtering and instant previews thanks to a modern, modular component architecture. Custom Asset Management: A dedicated admin workflow for uploading, organizing, and tagging custom SVG assets for your specific projects. Designer-Friendly Interface: A clean, responsive UI that makes asset evaluation simple for both technical and creative team members. #SVGIconsStock #WebDev #UIUX #NextJS #Frontend #DesignSystem #SVGIconsStock #SVG #WebDevelopment #DeveloperTools #ReactJS #UIUXDesign #OpenSource #Productivity #NextJS #FrontendWorkflow
To view or add a comment, sign in
-
-
Ever wanted to open a modal without leaving the page… but still keep a real URL? That’s exactly where Next.js Intercepting Routes quietly change the game. After working deeply with Next.js in real production apps, this is one of those features that feels small at first… but completely shifts how you design UX. Let’s break it down simply. Intercepting Routes let you “intercept” navigation and render a different route than what the URL suggests without actually leaving the current layout. What this really means is: You can show content like a modal, drawer, or overlay while still updating the URL. Example use case: You’re on a feed page → you click a post → instead of navigating away, it opens in a modal But the URL becomes /post/123 Refresh the page? Now it loads as a full page. That’s powerful. How it works (conceptually): Next.js uses a special folder pattern like: (.) or (…) This tells the router: Hey, render this route here temporarily instead of fully navigating. So you get: • Shared layout stays intact • UI feels instant • URL remains meaningful Why this matters: → Better UX No hard page transitions. Everything feels fluid. → Real URLs Users can share, bookmark, and reload seamlessly. → Cleaner architecture You don’t need hacks with state-heavy modal logic anymore. Common patterns you can build: • Image preview modals • Product quick views • Auth popups (login/signup) • Side drawers with details • Nested content without losing context Things to watch out for: • It can get confusing if you don’t plan your route structure well • Debugging parallel + intercepting routes together needs clarity • SEO behavior depends on fallback routes (don’t ignore this) Intercepting Routes aren’t just a routing feature. They’re a UX upgrade baked into your architecture. Once you start using this properly, going back to traditional routing feels… limiting. Have you tried Intercepting Routes in your project yet? #NextJS #WebDevelopment #Frontend #ReactJS #FullStack #JavaScript #UX #WebDev #SoftwareEngineering #DevTips
To view or add a comment, sign in
-
-
✨ 𝐆𝐨𝐨𝐝 𝐅𝐫𝐨𝐧𝐭𝐞𝐧𝐝 𝐯𝐬. 𝐆𝐫𝐞𝐚𝐭 𝐅𝐫𝐨𝐧𝐭𝐞𝐧𝐝: 𝐓𝐡𝐞 𝐏𝐨𝐰𝐞𝐫 𝐨𝐟 𝐌𝐢𝐜𝐫𝐨-𝐃𝐞𝐭𝐚𝐢𝐥𝐬 We spend a lot of time debating frameworks—Next.js vs. React, Tailwind vs. CSS Modules. But at the end of the day, users don't care about our stack. They care about how the application feels. I’ve found that taking a UI from "good" to "great" usually comes down to a few small, deliberate details: 🔹 𝐒𝐤𝐞𝐥𝐞𝐭𝐨𝐧𝐬 𝐨𝐯𝐞𝐫 𝐒𝐩𝐢𝐧𝐧𝐞𝐫𝐬: Replacing a generic loading circle with a skeleton UI reduces perceived waiting time and keeps the user grounded. 🔹 𝐏𝐫𝐞𝐝𝐢𝐜𝐭𝐚𝐛𝐥𝐞 𝐇𝐨𝐯𝐞𝐫 𝐒𝐭𝐚𝐭𝐞𝐬: Buttons should feel interactive before they are even clicked. A subtle transition on hover or focus adds immediate polish. 🔹 𝐆𝐫𝐚𝐜𝐞𝐟𝐮𝐥 𝐄𝐫𝐫𝐨𝐫 𝐇𝐚𝐧𝐝𝐥𝐢𝐧𝐠: "An error occurred" helps no one. Guiding the user back to safety with clear, actionable UI states builds trust. Great frontend development is about empathy for the end-user. 👇 𝐋𝐞𝐭’𝐬 𝐝𝐢𝐬𝐜𝐮𝐬𝐬: What is one small UI detail that instantly makes a website feel more premium to you? #FrontendDevelopment #UIUX #WebDesign #ReactJS #TailwindCSS #UserExperience #SoftwareDeveloper #SoftwareEngineering
To view or add a comment, sign in
-
-
𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁 𝘃𝘀 𝘂𝘀𝗲𝗟𝗮𝘆𝗼𝘂𝘁𝗘𝗳𝗳𝗲𝗰𝘁 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 — 𝗖𝗵𝗼𝗼𝘀𝗶𝗻𝗴 𝘁𝗵𝗲 𝗥𝗶𝗴𝗵𝘁 𝗛𝗼𝗼𝗸 𝗮𝘁 𝘁𝗵𝗲 𝗥𝗶𝗴𝗵𝘁 𝗧𝗶𝗺𝗲 React gives developers powerful hooks to manage side effects, but understanding when each hook runs can make a significant difference in UI performance and user experience. Two commonly misunderstood hooks are: 🔹 𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁() useEffect runs after the browser has painted the UI. This makes it the right choice for: • API requests • Event listeners • Subscriptions • Logging • Updating external systems Because it runs after paint, it does not block rendering, helping keep your application fast and responsive. 🔹 𝘂𝘀𝗲𝗟𝗮𝘆𝗼𝘂𝘁𝗘𝗳𝗳𝗲𝗰𝘁() useLayoutEffect runs immediately after the DOM updates but before the browser paints the screen. This makes it useful for: • Reading element dimensions • Measuring layout • Scroll position adjustments • Preventing visual flicker • Synchronizing DOM changes before display Since it runs before paint, users never see intermediate layout changes. 𝗪𝗵𝘆 𝗶𝘁 𝗺𝗮𝘁𝘁𝗲𝗿𝘀 Using the wrong hook can lead to: ❌ Layout shifts ❌ Flickering UI ❌ Incorrect measurements ❌ Less predictable rendering behavior Choosing the correct hook leads to: ✅ Smoother interfaces ✅ Better visual stability ✅ More predictable components 𝗦𝗶𝗺𝗽𝗹𝗲 𝗿𝘂𝗹𝗲 𝗼𝗳 𝘁𝗵𝘂𝗺𝗯 Use useEffect → for most side effects Use useLayoutEffect → when layout or visual updates must happen before paint Small React details like this often separate working code from polished frontend engineering. #React #JavaScript #FrontendDevelopment #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
When I started frontend, I wasn’t using any UI libraries. Everything was just custom CSS. Took time, things broke a lot but honestly that helped me understand basics better. Then slowly I started exploring different libraries… Tried Tailwind, shadcn, and many UI tools. At first it felt confusing — too many options in the market. But after using them, one thing became clear: There’s no “best” UI library. Every library has its own use case. Some are fast, some are flexible, some are just good for specific things. Now I just do this: 1. First decide what kind of UI I want to build 2. Then pick tools based on that These are some libraries/tools I explored 👇 Origin UI → https://originui.com MVPBlocks → https://lnkd.in/g5BHAHza Skiper UI → https://skiper-ui.com Ant Design → https://ant.design Cult UI → https://cult-ui.com Eldora UI → https://eldoraui.site shadcn/ui → https://ui.shadcn.com Tailark → https://tailark.com SmoothUI → https://smoothui.dev Pattern Craft → https://patterncraft.fun I use this for my UI reference Landing Page Inspiration → https://land-book.com Right now I mostly use Tailwind + shadcn, and add other things only when needed. Still learning, still figuring things out 🚀 #frontend #reactjs #tailwindcss #webdev
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