<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vihanga Thalangedara on Medium]]></title>
        <description><![CDATA[Stories by Vihanga Thalangedara on Medium]]></description>
        <link>https://medium.com/@vihangathalangedara?source=rss-1fdea08bfb8a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1adOMTZww3qnPeUNz1NC3g.jpeg</url>
            <title>Stories by Vihanga Thalangedara on Medium</title>
            <link>https://medium.com/@vihangathalangedara?source=rss-1fdea08bfb8a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:40:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vihangathalangedara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Visible Labels ≠ Accessible Names: A Frontend Accessibility Lesson]]></title>
            <link>https://medium.com/@vihangathalangedara/visible-labels-accessible-names-a-frontend-accessibility-lesson-4a220fbdf14b?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a220fbdf14b</guid>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[webaccessibilitystandards]]></category>
            <category><![CDATA[a11y]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Sun, 11 Oct 2026 17:23:47 GMT</pubDate>
            <atom:updated>2026-10-11T17:28:07.556Z</atom:updated>
            <content:encoded><![CDATA[<p>aria-labelledby vs aria-label</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOJRpl6PPUyB_FhAiLX2cw.png" /></figure><p>While working on a UI recently, I came across an accessibility issue that reminded me of something important: <strong>what looks clear on screen isn’t always communicated clearly to everyone using the interface.</strong></p><p>It was a small issue in the markup, but understanding it helped me think more carefully about how I build accessible user interfaces.</p><p>In this article, I’ll share the problem I encountered, the possible solutions I considered, and why I chose aria-labelledby to address it.</p><h3>The Problem: Clear to See, Unclear to Hear</h3><p>Imagine a UI containing a set of buttons. Each button displays a short value, such as <strong>A, B, or C</strong>, and a descriptive label appears just below it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*HpL1n64P5LvGl-e9gYFB5w.png" /></figure><p>For example:</p><ul><li><strong>A</strong> — View monthly report</li><li><strong>B</strong> — Manage users</li><li><strong>C</strong> — Download data</li></ul><p>For sighted users, the interface is easy to understand. They can see the short value on each button and read the descriptive text underneath it.</p><p>However, when navigating the interface using a screen reader, I noticed that only the short value was announced when a button received focus.</p><p>A user might hear something like “A, button” without receiving the additional context that explains what the button does.</p><p>The descriptive text was visible on the page, but it wasn’t associated with the button’s accessible name.</p><blockquote>This highlighted an important distinction: <strong>a label can be visually close to an interactive element without being programmatically connected to it.</strong></blockquote><h3>Understanding Visible Labels and Accessible Names</h3><p>An accessible name is the name assistive technologies use to identify an interface element. For a button, it helps users understand what the button represents or what action it performs.</p><p>A button might contain text, receive a name through an ARIA attribute, or derive its name from another element referenced in the markup.</p><p>For example:</p><pre>&lt;button id=&#39;value-a&#39;&gt;A&lt;/button&gt;<br>&lt;span id=&#39;label-a&#39;&gt;View monthly report&lt;/span&gt;</pre><p>Although the descriptive text appears directly below the button, the browser doesn’t automatically treat that text as part of the button’s accessible name.</p><p>The button’s accessible name remains “A”.</p><p>To provide the missing context, I needed a way to associate the descriptive text with the button while keeping the existing visual design unchanged.</p><h3>Exploring Possible Solutions</h3><p>Before choosing an approach, I considered four possible solutions.</p><h3>1. Using aria-labelledby</h3><p>The aria-labelledby attribute allows an element to use the text of another element—or multiple elements—as its accessible name by referencing their <strong>IDs</strong>.</p><p>For example:</p><pre>&lt;button id=&quot;value-a&quot; aria-labelledby=&quot;value-a label-a&quot;&gt; A &lt;/button&gt;<br>&lt;span id=&quot;label-a&quot;&gt;View monthly report&lt;/span&gt;</pre><p>Here, the button references both the short value and the descriptive label. Its accessible name becomes <strong>“A View monthly report”</strong>.</p><p>This approach allows us to reuse text that already exists in the interface instead of writing the same description again.</p><h3>2. Using aria-label</h3><p>Another option is to provide an accessible name directly using aria-label.</p><pre>&lt;button id=&quot;value-a&quot; aria-label=&quot;A, View monthly report&quot;&gt; A &lt;/button&gt;<br>&lt;span id=&quot;label-a&quot;&gt; View monthly report&lt;/span&gt;</pre><blockquote>This gives the button an explicit accessible name without changing the visible design.</blockquote><p>However, the accessible name is maintained separately from the visible text. <strong>If the visible label changes later</strong>, the aria-label <strong>may need to be updated as well.</strong></p><p>That means extra care is needed to keep the accessible name consistent with the interface.</p><h3>3. Moving the Descriptive Label Inside the Button</h3><p>We could also place the descriptive text directly inside the button:</p><pre>&lt;button&gt;<br>  A<br>  &lt;span&gt;View monthly report&lt;/span&gt;<br>&lt;/button&gt;</pre><p>This is a straightforward approach because the button’s text content can contribute to its accessible name.</p><p>However, in an existing interface, moving the label inside the button could <strong>affect the current layout or stylin</strong>g. Whether this is suitable depends on the design and interaction requirements.</p><h3>4. Adding Visually Hidden Text</h3><p>Another possibility is to include additional text specifically for assistive technologies while keeping it visually hidden.</p><p>For example:</p><pre>&lt;button&gt;<br>  A<br>  &lt;span class=&quot;visually-hidden&quot;&gt;<br>    View monthly report<br>  &lt;/span&gt;<br>&lt;/button&gt;</pre><p>The visually-hidden class would <strong>need appropriate CSS</strong> <strong>to hide the text</strong> visually while keeping it available to screen readers. It should not use display: none or visibility: hidden, as those typically remove the text from the accessibility tree.</p><p><strong>This can be useful when extra context is needed without changing the visual appearance</strong>. However, in this case, the descriptive text already existed on the page, so adding another copy wasn’t necessary.</p><h3>Why I Chose aria-labelledby</h3><p>After considering the alternatives, I chose <strong>aria-labelledby</strong> because it fit the existing UI and addressed the actual problem.</p><p>The<strong> descriptive labels were already present in the markup</strong>. By referencing the IDs of both the short value and its corresponding description, I could <strong>include the necessary context in the button’s accessible name without duplicating text or changing the visual layout.</strong></p><p>This approach also made the relationship between the button and its description explicit in the markup.</p><p>The result was a more meaningful announcement for screen reader users: instead of hearing only the short value, they could hear the value together with its description.</p><blockquote>Of course, the best solution depends on the context. If the descriptive text were not already available, aria-label or another approach might be more appropriate. The important part is choosing a solution that works for both the interface and its users.</blockquote><h3>What I Learned</h3><p>This experience reinforced a few lessons for me as a frontend developer.</p><p><strong>1. Visual clarity doesn’t guarantee accessibility.</strong></p><p>An interface can look intuitive while still leaving users of assistive technologies without important information.</p><p><strong>2. Existing text can be useful for accessibility.</strong></p><p>Before adding new labels or duplicating content, it’s worth checking whether the necessary information already exists and can be associated correctly.</p><p><strong>3. Accessibility decisions deserve the same thought as visual decisions.</strong></p><p>Choosing between aria-label, aria-labelledby, and a markup change isn&#39;t just about knowing the attributes. It&#39;s about understanding the context, the existing structure, and the experience we want to provide.</p><p><strong>4. Small markup changes can make a meaningful difference.</strong></p><p>Sometimes, improving accessibility doesn’t require redesigning an entire component. A carefully chosen change can provide users with the context they need.</p><h3>Final Thoughts</h3><p>It is important thinking about how different people experience those interfaces.</p><p>The next time I want to remember to ask myself one additional question:</p><p><strong>Does this element communicate its purpose clearly to everyone who uses it, including people who rely on assistive technologies?</strong></p><p>Because building a better user experience means making sure that the experience works for more than just the people who can see the screen.</p><p><em>Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a220fbdf14b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP Status Codes Explained Using One Real Web App Scenario]]></title>
            <link>https://medium.com/@vihangathalangedara/http-status-codes-explained-using-one-real-web-app-scenario-a613bbd0785c?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a613bbd0785c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[http-status-code]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Sun, 14 Jun 2026 11:08:36 GMT</pubDate>
            <atom:updated>2026-06-14T11:08:36.959Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOR-CBDkzUCQVfNYv6KEaw.png" /></figure><p>Have you ever noticed those numbers that show up when something goes wrong on a website — like <strong>404</strong>, <strong>500</strong>, or sometimes even <strong>200 OK</strong>?</p><p>Most of the time, we ignore them. But as developers, these small numbers actually tell the full story of what is happening behind the scenes in a web application.</p><p>Let’s understand them using a real-world example.</p><blockquote>We’ll imagine a simple E<strong>-commerce web application</strong> where users can register, log in, browse products, and place orders. And we’ll see how <strong>HTTP status codes</strong> appear in each situation.</blockquote><h3>1. What are the main categories of HTTP status codes we use?</h3><p>In any web application, HTTP responses are grouped into three major categories:</p><ul><li><strong>2xx → Success (everything worked)</strong></li><li><strong>4xx → Client errors (user did something wrong)</strong></li><li><strong>5xx → Server errors (something went wrong in backend)</strong></li></ul><h3>2. What are the commonly used 2xx success codes?</h3><p>These mean everything worked as expected.</p><h4>🟢 200 OK</h4><p>This means the request was successful and data is returned.</p><blockquote><strong>Example in our app:</strong><br> A user opens the homepage and the system fetches the product list.</blockquote><blockquote>👉 Products are successfully displayed.</blockquote><h4>🟢 201 Created</h4><p>This means a new resource was successfully created.</p><blockquote><strong>Example in our app:</strong><br> A user successfully registers a new account or places a new order.</blockquote><blockquote>👉 “Your account has been created” or “Order placed successfully”</blockquote><h4>🟢 204 No Content</h4><p>This means the request was successful but there is nothing to return.</p><blockquote><strong>Example in our app:</strong><br> A user deletes their account or removes an item from the cart.</blockquote><blockquote>👉 Action is done, but no response data is needed.</blockquote><h3>3. What are the commonly used 4xx client error codes?</h3><p>These mean the problem is from the user side (wrong request, missing access, etc.)</p><h4>🔴 400 Bad Request</h4><p>The request sent by the user is invalid.</p><blockquote><strong>Example in our app:</strong><br> User tries to place an order without selecting a product quantity.</blockquote><blockquote>👉 Backend rejects the request due to missing/invalid data.</blockquote><h4>🔐 401 Unauthorized</h4><p>The user is not logged in.</p><blockquote><strong>Example in our app:</strong><br> User tries to view their order history without logging in.</blockquote><blockquote>👉 System asks them to log in first.</blockquote><h4>🚫 403 Forbidden</h4><p>The user is logged in but not allowed to access the resource.</p><blockquote><strong>Example in our app:</strong><br> A normal user tries to access the admin dashboard.</blockquote><blockquote>👉 Access is blocked even though they are authenticated.</blockquote><h4>🔍 404 Not Found</h4><p>The requested resource does not exist.</p><blockquote><strong>Example in our app:</strong><br> User tries to open a product page that has been deleted or never existed.</blockquote><blockquote>👉 “Product not found”</blockquote><h3>4. What are the commonly used 5xx server error codes?</h3><p>These mean something went wrong on the server side.</p><h4>💥 500 Internal Server Error</h4><p>Something unexpected broke in the backend.</p><blockquote><strong>Example in our app:</strong><br> Database crashes while placing an order.</blockquote><blockquote>👉 User sees “Something went wrong, try again later”</blockquote><h4>🌐 502 Bad Gateway</h4><p>The server acting as a gateway received an invalid response.</p><blockquote><strong>Example in our app:</strong><br> API gateway tries to fetch product data from another microservice, but it fails.</blockquote><blockquote>👉 Backend service communication issue.</blockquote><h4>⏳ 503 Service Unavailable</h4><p>The server is temporarily down or overloaded.</p><blockquote><strong>Example in our app:</strong><br> During a big sale (like Black Friday), the website cannot handle traffic.</blockquote><blockquote>👉 Users see “Service temporarily unavailable”</blockquote><h3>Key Takeaways:</h3><p>Using a single real-world system like an e-commerce app makes HTTP status codes much easier to understand and remember.</p><p>Instead of memorizing codes, think of them as <strong>communication messages between frontend and backend</strong>:</p><ul><li>“Everything worked”</li><li>“You did something wrong”</li><li>“Server failed”</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a613bbd0785c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[❇️ How I approached a React multi-step form wizard in a coding challenge — Part I]]></title>
            <link>https://medium.com/@vihangathalangedara/%EF%B8%8F-how-i-approached-a-react-multi-step-form-wizard-in-a-coding-challenge-part-i-b4c7fcd7899a?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4c7fcd7899a</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Sat, 09 May 2026 12:39:17 GMT</pubDate>
            <atom:updated>2026-05-09T12:39:17.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7npnEN_r5e6v70gl3U1nog.png" /></figure><p>Recently, I worked on a frontend coding challenge focused on building a multi-step onboarding wizard with validations, file uploads, state persistence, and a review flow.</p><p>Before starting the implementation, I focused on understanding the problem by asking myself a few key questions.</p><h3>🔷1. What is the flow of the wizard?</h3><p>I identified the user journey as:<br> Step 1 → Personal Info<br> Step 2 → Skills &amp; Avatar<br> Step 3 → Review &amp; Submit<br> Success Screen</p><p>From this, I understood:<br> • <strong>Only one step </strong>should be visible <strong>at a time</strong><br> • <strong>Navigation </strong>must be controlled<br> • <strong>Validation </strong>should block progression</p><h3>🔷 2. Where should the state live?</h3><p>Since users can go back and edit data, keeping state inside each step would not be enough.</p><p>So I decided to keep all form data in a<em> </em><strong><em>parent wizard component</em></strong> and let child components handle only UI and interactions.</p><h3>🔷 3. How does data flow?</h3><p>The pattern became:</p><p><strong>User Input → Child Component → Parent State Update → Re-render</strong></p><p>This made the parent the “single source of truth”. Each step becomes a child component responsible for rendering its section and updating the parent state.</p><h3>🔷 4. How to track progress?</h3><p>A simple `<strong>currentStep</strong>` state in the parent controls navigation and decides which step should be rendered.</p><h3>🔷5. What about editing from the review screen?</h3><p>Instead of editing directly in the preview, I decided users should be taken back to the relevant step component and update there. This avoids duplicating logic and keeps the flow cleaner.</p><h3>🔷6. What are the edge cases?</h3><p>Before implementation, I listed possible issues:<br>• Input validation<br>• Invalid file uploads<br>• Dynamic skills based on selected role<br>• Back navigation while preserving data</p><h3>💡 <strong>Big takeaway</strong></h3><p><strong>Good implementation starts with structured thinking. — </strong>Breaking down the flow, state ownership, data flow, and edge cases before coding helped me build with more clarity and confidence.</p><p>In Part 2, I’ll share how I implemented this wizard in React.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4c7fcd7899a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Bootstrap in 5 Minutes: Start with a Simple Button Example]]></title>
            <link>https://medium.com/@vihangathalangedara/ever-wanted-to-learn-about-bootstrap-6e4862430bef?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e4862430bef</guid>
            <category><![CDATA[bootstrap]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[styling]]></category>
            <category><![CDATA[customization]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 08:06:49 GMT</pubDate>
            <atom:updated>2026-03-16T09:19:51.129Z</atom:updated>
            <content:encoded><![CDATA[<p>When building websites, styling elements from scratch using <strong>plain CSS</strong> can be <strong>time-consuming and repetitive</strong>. That’s where <strong>Bootstrap</strong> comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zq05m2B8rfsu88uOrjG20g.png" /></figure><p>In this article, you’ll get a <strong>beginner-friendly guide</strong> to Bootstrap.</p><h3>What is Bootstrap?</h3><p><strong>Bootstrap</strong> is a front-end CSS framework originally developed by engineers at Twitter. It provides <strong>predefined component classes.</strong></p><h4>What are Predefined Component Classes?</h4><p>Bootstrap has <strong>ready-made styles for common UI elements</strong> like:</p><ul><li>Buttons</li><li>Navbars</li><li>Cards</li><li>Alerts</li><li>Forms</li></ul><h4>How do developers use these classes?</h4><p>Developers use these classes by adding them directly to<strong> class attribute</strong> in <strong>HTML elements</strong>.</p><h3>Simple Bootstrap Button Example:</h3><pre>&lt;button class=&quot;btn btn-primary&quot;&gt;Primary&lt;/button&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/116/1*GHxNFSaCEbTEuEDJNeJ97g.png" /></figure><p>Below are the bootstrap classes used here:</p><p>btn- <strong>Base button styling </strong>provided by Bootstrap</p><p>btn-primary - Applies the <strong>primary color (blue) and additional styling</strong></p><p>This gives you a <strong>fully styled button</strong> with hover effects, padding, and rounded corners and all without writing custom CSS.</p><h3>Can we customize Bootstrap’s predefined classes?</h3><p>Yes. otherwise all the applications which use given bootstrap styles are looking similar.</p><h3>How can we customize Bootstrap Components?</h3><p>There are a couple of ways to customize Bootstrap components.</p><h4>1. Using a Custom Class</h4><p>Here we can add your own class to override specific properties:</p><p>Lets take an example, you may want to <strong>change the padding and font size</strong> of a button.</p><p>HTML file:</p><pre>&lt;button class=&quot;btn btn-primary custom-btn&quot;&gt;Submit&lt;/button&gt;</pre><p>CSS file:</p><pre>.custom-btn {<br>  padding: 12px 24px; /* custom padding */<br>  font-size: 18px;   /* custom font size */<br>}</pre><p>Here’s what happens:</p><ul><li>btn → <strong>keeps Bootstrap base styles</strong></li><li>btn-primary → <strong>color variant</strong></li><li>custom-btn → <strong>overrides only the properties you want </strong>(padding, font size)</li></ul><h4>What about using just custom-btn without btn and btn-primary?</h4><p>You <strong>can</strong> use only custom-btn without btn btn-primary.</p><p>But then you <strong>lose Bootstrap’s base button styling</strong>. It is similar to use plain css. To customize Bootstrap’s predefined styles, we usually keep <strong>btn</strong> to <strong>retain base styling</strong> and add a<strong> custom class</strong> for tweaks.</p><h4>2. Combining Custom Class and Utility Classes</h4><p>Bootstrap also provides <strong>utility classes</strong> for quick spacing and sizing adjustments. You can combine them with your custom class:</p><pre>&lt;button class=&quot;btn btn-primary custom-btn px-5 py-3 me-2&quot;&gt;<br>  Submit<br>&lt;/button&gt;</pre><p>btn →Base Bootstrap button styling</p><p>btn-primary→Primary color variant</p><p>custom-btn→Custom font size, padding, border-radius</p><p>px-5→Override horizontal padding</p><p>py-3→Override vertical padding</p><p>me-2→Margin-end (space to next element)</p><h3>Do Bootstrap Utilities <strong>Override Existing Values?</strong></h3><p>Yes. Bootstrap utility classes like</p><p>px-* (horizontal padding) and</p><p>py-* (vertical padding) <strong>override the padding set by </strong><strong>.btn or other classes</strong>.</p><h4>Example:</h4><p>suppose you have combined custom class with utility classes too.</p><p>HTML file:</p><pre>&lt;button class=&quot;btn btn-primary custom-btn px-5 py-3&quot;&gt;<br>  Submit<br>&lt;/button&gt;</pre><p>CSS file:</p><pre>.custom-btn {<br>  padding: 12px 24px;<br>}</pre><p>In this case, a <strong>conflict </strong>arises:</p><ul><li>.custom-btn sets padding: 12px 24px;</li><li>px-5 py-3 sets padding according to Bootstrap’s utility values</li></ul><h4>What is the order of applying CSS</h4><p>CSS applies based on the order in the stylesheet:</p><ol><li>If your custom CSS is <strong>loaded after Bootstrap</strong>, .custom-btn will override px-5/py-3.</li><li>If the HTML order or CSS order keeps px-5 py-3 last, then the utilities will <strong>override the custom class</strong>.</li></ol><p>✅ Pro Tip: In practice, developers usually <strong>choose one method per property</strong> to avoid confusion:</p><ul><li>Use <strong>utility classes for quick spacing tweaks</strong></li><li>Use <strong>custom class for custom styling like font-size, border-radius, and padding</strong></li><li>Avoid mixing both for the same property unless necessary</li></ul><h3>Why Use Bootstrap?</h3><ul><li><strong>Saves time</strong>: Predefined classes let you quickly build UI components.</li><li><strong>Responsive by default</strong>: Built-in grid system and responsive utilities.</li><li><strong>Consistency</strong>: Maintains a consistent look across pages.</li><li><strong>Easy to learn</strong>: Simple class-based system for beginners.</li></ul><h3>Key Takeaways</h3><ul><li>Bootstrap is perfect if you want <strong>ready-made components</strong> and quick styling.</li><li>For <strong>highly customized designs</strong>, you can override or extend Bootstrap classes.</li><li>Understanding Bootstrap classes helps you <strong>move to other frameworks</strong> like Tailwind or React-based libraries like MUI.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e4862430bef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bootstrap vs Tailwind CSS vs Material : Understanding Their Differences and When to Use Each]]></title>
            <link>https://medium.com/@vihangathalangedara/bootstrap-vs-tailwind-css-vs-material-understanding-their-differences-and-when-to-use-each-0f80a833e346?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f80a833e346</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[boostrap]]></category>
            <category><![CDATA[bootstrap]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 05:51:21 GMT</pubDate>
            <atom:updated>2026-03-09T06:16:27.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pE9gqdcCb_7FOHJocppNiQ.png" /></figure><p>Have you ever compared <strong>Bootstrap, Tailwind CSS, </strong>and <strong>Material UI</strong>?</p><p>In this article, you’ll learn how developers <strong>initially styled websites using plain CSS</strong> and how <strong>modern frameworks </strong>and <strong>UI libraries </strong>evolved to make frontend development faster and more efficient.</p><h3>How Did Developers Initially Style Websites?</h3><p>Before modern tools like Bootstrap, Tailwind CSS, or Material UI existed, developers styled websites using <strong>raw CSS (Cascading Style Sheets)</strong>.</p><p>They manually wrote CSS rules and applied them to HTML elements. Below are the ways.</p><h4>1. Inline CSS (Early Method)</h4><p>Here styles were written <strong>directly inside HTML elements</strong>.</p><pre>&lt;button style=&quot;background-color: blue; color: white; padding: 10px;&quot;&gt;<br>  Submit<br>&lt;/button&gt;</pre><p><strong>Limitations with this approach:</strong></p><ul><li>Hard to maintain</li><li>Repetitive code</li><li>Difficult to update styles across many pages</li></ul><h4>2. Internal CSS (Inside the HTML File)</h4><p>Here developers started placing styles inside a &lt;style&gt; tag within the HTML file.</p><pre>&lt;style&gt;<br>.button {<br>  background-color: blue;<br>  color: white;<br>  padding: 10px;<br>}<br>&lt;/style&gt;</pre><pre>&lt;button class=&quot;button&quot;&gt;Submit&lt;/button&gt;</pre><p><strong>Pros:</strong></p><ul><li>styles were separated from elements</li><li>easier to reuse classes</li></ul><p><strong>Cons:</strong></p><ul><li>Difficult when websites became larger.</li></ul><h4>3. External CSS Files (Modern Traditional Approach)</h4><p>This is the most common approach. Here we use external CSS file.</p><p><strong>Html file:</strong></p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt;</pre><pre>&lt;button class=&quot;button&quot;&gt;Submit&lt;/button&gt;</pre><p><strong>CSS file:</strong></p><pre>.button {<br>  background-color: blue;<br>  color: white;<br>  padding: 10px;<br>  border-radius: 6px;<br>}</pre><p><strong>Pros:</strong></p><ul><li>Clean separation between HTML and CSS</li><li>Reusable styles across multiple pages</li><li>Easier maintenance</li></ul><p><strong>Cons:</strong></p><ul><li>As web applications grew more complex, developers had to write <strong>thousands of lines of CSS. -&gt; </strong>it became difficult to manage.</li></ul><h3>Why Do We Need CSS Frameworks and UI Libraries?</h3><p>As projects became larger, developers faced several problems:</p><ul><li>Repeating the same styles across projects</li><li>Writing CSS for common components (buttons, cards, navbars)</li><li>Managing responsive design manually</li><li>Maintaining design consistency across teams</li></ul><p>To solve this problem, developers use <strong>CSS frameworks(Bootstrap</strong>, <strong>Tailwind CSS )and UI libraries (MUI) </strong>that provide pre-built styles and components.</p><h3>What is Boostrap?</h3><p>Bootstrap is one of the oldest and most widely used <strong>CSS frameworks.</strong> Originally developed by engineers at <strong>Twitter</strong>.</p><p>Bootstrap provides a collection of <strong>ready-to-use UI components and layout utilities</strong>.</p><p>It includes <strong>built-in styles</strong> for:</p><ul><li>Buttons</li><li>Navigation bars</li><li>Forms</li><li>Cards</li><li>Modals</li><li>Responsive grid layouts</li></ul><p><strong>Lets see an example button:</strong></p><pre>&lt;button class=&quot;btn btn-primary&quot;&gt;Primary&lt;/button&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/121/1*XOeuZMM2RLnnxWaq5c5TEg.png" /></figure><p><strong>btn and </strong><strong>btn-primary classes</strong> apply Bootstrap’s <strong>built-in button styles.</strong></p><p><strong>Advantages of Bootstrap</strong></p><ul><li>Very easy to learn</li><li>Large collection of UI components</li><li>Strong documentation and community support</li><li>Great for rapid prototyping</li></ul><p><strong>Limitations of Bootstrap</strong></p><ul><li>Websites can look very similar if heavily relying on default styles</li><li>Customization can sometimes be difficult</li><li>CSS bundle size can be relatively large</li></ul><h3>What is Tailwind CSS?</h3><p>Tailwind CSS is a <strong>utility-first CSS framework. </strong>Tailwind provides <strong>small utility classes</strong> that perform a single styling function.</p><p>Developers combine these utilities to design interfaces directly within the HTML.</p><pre>&lt;button class=&quot;bg-blue-500 text-white px-4 py-2 rounded&quot;&gt; Defalt&lt;/button&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/1*d-KI5aRMNRD-hq4VANrPJw.png" /></figure><p>Here each class represents a specific style:</p><ul><li><strong>bg-blue-500</strong> → background color</li><li><strong>text-white</strong> → text color</li><li><strong>px-4 py-2 </strong>→ padding</li><li><strong>rounded </strong>→ border radius</li></ul><p>This allows to build <strong>highly customizable designs without writing traditional CSS files</strong>.</p><p><strong>Advantages of Tailwind CSS</strong></p><ul><li>Highly customizable</li><li>Smaller production CSS bundle</li><li>Encourages consistent design systems</li><li>Works extremely well with modern frameworks like React and Next.js</li></ul><p><strong>Limitations of Tailwind CSS</strong></p><ul><li>HTML can become crowded with many classes</li><li>Initial learning curve</li><li>Developers must build their own components</li></ul><p>Tailwind CSS is widely used in <strong>modern startups, SaaS platforms, and React-based applications</strong>.</p><h4>Meaning of “utility-first CSS framework” ?</h4><p>A <strong>utility-first CSS framework</strong> means a framework that provides <strong>small, single-purpose CSS classes (utilities)</strong> that you combine to build your design directly in the HTML/JSX. It is not writing custom CSS.</p><h3>What is Material UI (MUI)?</h3><p>Material UI (MUI) is a <strong>React component library</strong> based on Google’s Material Design system.</p><p>Unlike Bootstrap and Tailwind, MUI is built specifically for React applications and provides <strong>ready-made React components</strong> rather than CSS classes.</p><pre>import Button from &#39;@mui/material/Button&#39;;</pre><pre>function App() {<br>  return &lt;Button variant=&quot;contained&quot;&gt;Contained&lt;/Button&gt;;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*7Y1QusIcOl68scu76wZnGA.png" /></figure><p><strong>Advantages of MUI</strong></p><ul><li>Professionally designed components</li><li>Excellent integration with React</li><li>Strong accessibility support</li><li>Consistent UI across applications</li></ul><p><strong>Limitations of MUI</strong></p><ul><li>Larger bundle size</li><li>Less flexibility compared to utility frameworks like Tailwind</li><li>Requires understanding of component APIs</li></ul><p>MUI is often used in <strong>enterprise React applications and professional dashboards</strong>.</p><h3>Lets see examples comparative</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8P80JgvhK69MUhhv9tG38A.png" /></figure><h3>Final Takeaways</h3><p><strong>Which One Should You Choose? </strong>The choice depends on your project requirements and development stack.</p><ul><li><strong>Use Bootstrap</strong> if you want a <strong>quick solution </strong>with <strong>ready-made components</strong>.</li><li><strong>Use Tailwind CSS</strong> if you want<strong> full design flexibility </strong>and are building <strong>modern frontend applications.</strong></li><li><strong>Use Material UI</strong> if you are developing a <strong>React application</strong> and want <strong>professional components with minimal design</strong> work.</li></ul><p>In many modern React projects, developers prefer combining <strong>React with Tailwind CSS</strong> for maximum flexibility and performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f80a833e346" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When React.memo Isn’t Enough: Preventing Unnecessary Re-renders with useCallback]]></title>
            <link>https://medium.com/@vihangathalangedara/when-react-memo-isnt-enough-preventing-unnecessary-re-renders-with-usecallback-272678ee7ead?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/272678ee7ead</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-usecallback]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[react-memo]]></category>
            <category><![CDATA[frontend-development]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Tue, 24 Feb 2026 18:25:04 GMT</pubDate>
            <atom:updated>2026-02-24T18:25:04.671Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTDwtZxxoR7AI9etJQvZtQ.png" /></figure><p>Have you ever noticed that React components receiving functions as props still re-render unnecessarily, even when wrapped with React.memo?</p><p>In this article, we’ll explore why this happens and how to fix it.</p><h4>🤔 When Does a React Component Re-render?</h4><p>A React component re-renders when:</p><ul><li>Its state changes</li><li>Its props change</li><li>Its context value changes</li><li>Its parent re-renders</li></ul><h4>🤔What Happens Every Time a Component Re-renders?</h4><p>React Components Are Functions.</p><p>Every time a component re-renders:</p><ul><li><strong>The component function</strong> runs again</li><li><strong>Variables </strong>are recreated</li><li><strong>Functions </strong>inside are recreated</li></ul><h4>🤔Explanation with an Example</h4><p>In this example, the Parent component has a count state and a function handleClick.</p><p>Every time Parent re-renders:</p><ul><li><strong>The component function</strong> runs again</li><li><strong>handleClick </strong>is recreated</li><li>It gets a <strong>new memory reference</strong></li><li>But the <strong>function logic remains identical</strong></li></ul><pre>function Parent() {<br>  const [count, setCount] = React.useState(0);<br><br>  const handleClick = () =&gt; {<br>    console.log(&quot;Clicked&quot;);<br>  };<br><br>  return (<br>    &lt;&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increase&lt;/button&gt;<br>      &lt;Child onClick={handleClick} /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h4>🤔If a child component receives a function prop like this, is it considered “changed” on every parent re-render?</h4><p>Yes.</p><p>Even though the function logic hasn’t changed, React sees the new reference as a changed prop.</p><h4>🤔Is this handled by React.memo and prevent child component rerendering?</h4><p>No.</p><h4>🤔Why doesn’t React.memo prevent re-renders when props are functions?</h4><p>Because with each parent component rerender, the function gets a new memory reference.</p><p>React.memo does shallow comparison. It does NOT compare function bodies. It compares references.</p><p>So even if the function logic is identical, React sees it as different.</p><p>So the child component re-renders.</p><h4>🎯 How Do We Fix This?</h4><p>We use useCallback to <strong>stabilize function references</strong>, so that React.memo can prevent unnecessary child re-renders. There are <strong>two main cases</strong>:</p><p><strong>1️⃣ Using </strong><strong>useCallback without dependencies</strong></p><pre>const handleClick = React.useCallback(() =&gt; {<br>  console.log(&quot;Clicked&quot;);<br>}, []);</pre><p>What happens:</p><ul><li>The function is <strong>created once</strong> on the first render.</li><li>On subsequent parent re-renders, the function reference <strong>stays the same</strong>.</li><li>React.memo sees the prop as <strong>unchanged</strong> → Child does <strong>NOT re-render</strong>.</li></ul><p>Problem solved when the function doesn’t rely on any external state.</p><p><strong>2️⃣ Using </strong><strong>useCallback with dependencies</strong></p><pre>const handleClick = React.useCallback(() =&gt; {<br>  console.log(&quot;Clicked&quot;, count);<br>}, [count]);</pre><p>What happens:</p><ul><li>The function is <strong>recreated only when </strong><strong>count changes</strong>.</li><li>If count hasn’t changed, the reference remains stable → Child does <strong>NOT re-render</strong>.</li><li>When count changes, the function reference updates → Child <strong>re-renders</strong> because the prop changed.</li></ul><p>This ensures the function always has the <strong>latest values</strong> while still preventing unnecessary renders.</p><h4>🤔 Is useCallback Recreating the Function?</h4><p>No.</p><p><strong>1️⃣ Without </strong><strong>useCallback:</strong></p><pre>Render → new function → new reference<br>Render → new function → new reference</pre><p>Every render:</p><ul><li>A new function object is created</li><li>New memory reference</li></ul><p><strong>2️⃣ With </strong><strong>useCallback (dependencies unchanged):</strong></p><pre>First render → create function<br>Next render → reuse same function reference</pre><p>It does NOT recreate the function unless dependencies change.</p><p>What React does internally:</p><ul><li>On first render → it creates the function and stores it.</li><li>On next render → it checks dependencies.</li><li>If dependencies didn’t change → it returns the previously stored function reference.</li><li>If dependencies changed → it creates a new function and stores that.</li></ul><p>So effectively:</p><p>👉 It prevents creating a new function on every render.<br>👉 It keeps the same reference between renders (if deps don’t change).</p><h4>🧩 Real-World Scenario</h4><p>Imagine:</p><ul><li>A large list component wrapped with React.memo</li><li>You pass event handlers like:</li><li>onDelete</li><li>onEdit</li><li>onSelect</li></ul><p><strong>1️⃣</strong>Without useCallback:</p><ul><li>Every parent render recreates those functions</li><li>All list items re-render</li><li>Performance drops</li></ul><p><strong>2️⃣</strong>With useCallback:</p><ul><li>Function references stay stable</li><li>Memoized children don’t re-render unnecessarily</li><li>App stays smooth</li></ul><h4>🧠 React.memo vs useMemo vs useCallback</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4Yrku42ngNMe8rlJqt5bA.png" /></figure><h4>⚠️ Should You Use useCallback Everywhere?</h4><p>No.</p><p>Use it when:</p><ul><li>Passing functions to memoized children</li><li>You have expensive child component</li><li>You need stable references (e.g., dependency arrays)</li></ul><p>Avoid it when:</p><ul><li>Component is small</li><li>No memoized children</li><li>No measurable performance issue</li></ul><p>Over-optimizing adds unnecessary complexity.</p><h4>🧠 Final Takeaways</h4><ul><li>Every re-render recreates functions inside the component</li><li>A new function means a new reference</li><li>A new reference means the prop is considered changed</li><li>Changed prop → memoized child re-renders</li><li>useCallback stabilizes function references</li><li>It works together with React.memo to prevent unnecessary re-renders</li></ul><p>Performance optimization in React is not about stopping renders entirely. It’s about preventing unnecessary work during renders.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=272678ee7ead" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Unnecessary Recalculations in React with useMemo]]></title>
            <link>https://medium.com/@vihangathalangedara/stop-unnecessary-recalculations-in-react-with-usememo-c22bd4e1218e?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c22bd4e1218e</guid>
            <category><![CDATA[react-usememo]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Sat, 21 Feb 2026 17:44:13 GMT</pubDate>
            <atom:updated>2026-02-24T06:38:43.265Z</atom:updated>
            <content:encoded><![CDATA[<p>“Ever wondered why some heavy computations in your React components keep running every time your app re-renders, even when nothing relevant has changed?”</p><p>This article dives into <strong>useMemo</strong>, a simple React Hook that helps you <strong>memoize calculations</strong> and boost your component performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVg4qzWrIjJJf1xzTXhbgA.png" /></figure><p>React components can re-render for several reasons:</p><ul><li>State changes</li><li>Props change</li><li>Context value changes</li><li>Parent component re-renders</li></ul><h4><em>Even if we cannot always prevent a component from re-rendering, can we prevent expensive calculations inside it from running again?</em></h4><p>Yes. That’s where <strong>useMemo</strong> comes in.</p><h4>🤔 What Problem Are We Solving?</h4><p>Whenever a React component re-renders, the entire function runs again.</p><p>That means:</p><ul><li><strong>Variables </strong>are re-created</li><li><strong>Functions </strong>are re-executed</li><li><strong>Calculations </strong>are recalculated</li></ul><p>If you have heavy computations (sorting, filtering, large transformations), they will run <strong>on every render</strong>, even if the data hasn’t changed.</p><p>This can slow down your app.</p><h4>🚀 What is useMemo?</h4><p>useMemo is a React Hook that <em>memoizes (caches) the result of a calculation and recomputes it only when its dependencies change.</em></p><p>It does NOT prevent re-renders.<br>It prevents <strong>unnecessary recalculations during re-renders</strong>.</p><h4>🔍 Real-World Example: Sorting Products</h4><p>Imagine an e-commerce dashboard showing hundreds of products.</p><pre>function ProductTable({ products }) {<br>  const [sortBy, setSortBy] = React.useState(&quot;price&quot;);<br><br>  const sortedProducts = [...products].sort((a, b) =&gt; {<br>    if (sortBy === &quot;price&quot;) return a.price - b.price;<br>    if (sortBy === &quot;rating&quot;) return b.rating - a.rating;<br>    return 0;<br>  });<br><br>  return (<br>    &lt;&gt;<br>      &lt;button onClick={() =&gt; setSortBy(&quot;price&quot;)}&gt;Sort by Price&lt;/button&gt;<br>      &lt;button onClick={() =&gt; setSortBy(&quot;rating&quot;)}&gt;Sort by Rating&lt;/button&gt;<br><br>      &lt;ul&gt;<br>        {sortedProducts.map(p =&gt; (<br>          &lt;li key={p.id}&gt;{p.name}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><h4>❌ What’s the problem?</h4><p>Every time this component re-renders (for any reason):</p><ul><li>The sorting runs again</li><li>Even if products and sortBy didn’t change</li></ul><p>That’s unnecessary work.</p><h4>✅ Optimizing with useMemo</h4><pre>const sortedProducts = React.useMemo(() =&gt; {<br>  console.log(&quot;Sorting products...&quot;);<br>  return [...products].sort((a, b) =&gt; {<br>    if (sortBy === &quot;price&quot;) return a.price - b.price;<br>    if (sortBy === &quot;rating&quot;) return b.rating - a.rating;<br>    return 0;<br>  });<br>}, [products, sortBy]);</pre><p>Now:</p><ul><li>The component may still re-render (for any reason)</li><li>But sorting only runs when products changes or sortBy changes.</li></ul><p>If a parent re-renders for unrelated reasons → sorting does NOT run again.</p><h4>🤔 Does useMemo Prevent Component Re-renders?</h4><p>No ❌ useMemo <strong>does NOT</strong> stop a component from re-rendering. It only <strong>prevents recalculating values during a re-render.</strong></p><h4>🧩 React.memo vs useMemo</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nie15vRaASaJpW4hl6sFtg.png" /></figure><h4>⚠️ Common Mistake with useMemo</h4><p>Always include all used variables in the dependency array.</p><p>Wrong:</p><pre>}, [sortBy]);</pre><p>Correct:</p><pre>}, [products, sortBy]);</pre><p>If products change and it&#39;s not in dependencies, you’ll get stale data.</p><h3>⚠️ Should You Use useMemo Everywhere?</h3><p>No.</p><p><strong>Use it when:</strong></p><ul><li>You have expensive computations</li><li>You are sorting/filtering large datasets</li><li>You are memoizing objects/arrays passed as props</li></ul><p><strong>Avoid it when:</strong></p><ul><li>Computation is cheap</li><li>Optimization gives no measurable benefit</li></ul><p><strong>Important: </strong>React re-renders are usually fast. Over-optimizing can add unnecessary complexity.</p><h3>🧠 Final Takeaways</h3><ul><li>Components re-render for many reasons</li><li>Re-rendering re-executes the component function</li><li><strong>useMemo prevents expensive recalculations during re-renders</strong></li><li>It<strong> does NOT prevent re-renders</strong></li><li>Use it intentionally for performance optimization</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c22bd4e1218e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tired of unnecessary child component re-renders when the parent updates but props stay the same?]]></title>
            <link>https://medium.com/@vihangathalangedara/tired-of-unnecessary-child-component-re-renders-when-the-parent-updates-but-props-stay-the-same-bc03868beb34?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc03868beb34</guid>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[props]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-memo]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 09:49:40 GMT</pubDate>
            <atom:updated>2026-02-16T09:49:40.533Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tired of unnecessary child component re-renders when the parent updates but props stay the same? Solution is <strong>React.memo</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96dewdcjT9ncFTDAgjTezQ.png" /></figure><p>React applications can become slow when child components re-render unnecessarily every time a parent updates. In this article, we’ll explore how React.memo helps optimize rendering by preventing child re-renders when their props haven’t changed.</p><h4>🤔 When Does a React Component Re-render?</h4><p>A React component re-renders when:</p><ol><li>Its <strong>state changes</strong></li><li>Its <strong>props change</strong></li><li>Its <strong>context value changes</strong></li><li>Its <strong>parent re-renders</strong></li></ol><p>Lets talk about “<strong>4. Its parent re-renders”</strong></p><h4>🤔 If Parent Re-renders, Does Child Re-render?</h4><p>Yes. Lets see an example.</p><p>Here in this example, the <strong>parent re-renders because </strong>its <strong>own state changes</strong>. (Remember, a parent can also re-render<strong> if it receives new props, context changes, or its own parent re-renders.</strong>)</p><pre>function Parent() {<br>  const [count, setCount] = React.useState(0);<br><br>  return (<br>    &lt;&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>        Increase<br>      &lt;/button&gt;<br>      &lt;Child /&gt;<br>    &lt;/&gt;<br>  );<br>}<br>export default Parent;</pre><pre>function Child() {<br>  console.log(&quot;Child rendered&quot;);<br>  return &lt;div&gt;Child Component&lt;/div&gt;;<br>}<br>export default Child;</pre><p>Every time the button is clicked:</p><p><strong>count state</strong> in Parent component is changed and then,</p><ul><li><strong>Parent component re-renders</strong></li><li><strong>Child component re-renders</strong></li></ul><p>Even though Child does not use the changing state of parent (count).</p><p><strong>Can we stop this behavior?</strong></p><p>Answer: Yes, using <strong>performance optimization technique</strong> -&gt; <strong>React.memo</strong></p><h4>🚀 What is React.memo?</h4><p>React.memo is a <strong>performance optimization technique</strong>.</p><p>“It memoizes a functional component and prevents unnecessary re-renders by performing a shallow comparison of props.”</p><h4>🤔 Does React.memo Prevent All Re-renders?</h4><p>❌ No.</p><p>It only prevents re-rendering when:</p><ul><li><strong>The parent re-renders </strong>(for any reason)</li><li><strong>AND the component’s props remain unchanged</strong></li></ul><h4>🤔 What Happens If a React.memo Component Has No Props?</h4><p>It does handle the <strong>“no props”</strong> and <strong>“has props” </strong>both scenarios.</p><h4>🔍 How React.memo Actually Works</h4><p>Lets talk about it with 2 cases.</p><p><strong>Case 1: If React.memo Component Has Props?</strong></p><p>Here child component is wrapped with React.memo:</p><pre>const Child = React.memo(function Child({ value }) {<br>  console.log(&quot;Child rendered&quot;);<br>  return &lt;div&gt;{value}&lt;/div&gt;;<br>});</pre><p>During a <strong>parent re-render</strong>:</p><ul><li>Parent re-renders (for any reason)</li><li>It performs a <strong>shallow comparison</strong>.</li><li>If props are <strong>equal</strong> → it <strong>skips rendering</strong> the component.</li><li>If props <strong>changed </strong>→ it <strong>re-renders</strong> the component.</li></ul><p><strong>Case 2: If React.memo Component Has No Props?</strong></p><pre>const Child = React.memo(function Child() {<br>  console.log(&quot;Child rendered&quot;);<br>  return &lt;div&gt;Hello&lt;/div&gt;;<br>});</pre><ul><li>Parent re-renders (for any reason)</li><li>React checks Child</li><li>Since Child has <strong>no props</strong>, React compares:</li></ul><pre>previousProps = {}<br>nextProps = {}</pre><p>They are equal. So React.memo <strong>skips re-rendering the Child</strong>.</p><h4>🧠 What is Shallow Comparison?</h4><p>Shallow comparison means:</p><ul><li><strong>Primitives are compared by value</strong>, so if the value is unchanged, React.memo prevents re-render.</li></ul><pre>&lt;Child data={ count } /&gt;</pre><pre>10 === 10 // true</pre><ul><li><strong>Objects and arrays</strong> are compared by<strong> reference</strong></li></ul><p>A new object is created every render.</p><pre>&lt;Child data={{ count }} /&gt;</pre><pre>{ a: 1 } === { a: 1 } // false</pre><p>Even if contents are identical, they are different objects in memory. So this will still cause re-render.</p><h4>⚠️ What React.memo Does NOT Prevent</h4><p>1. Component’s own state changes</p><p>2️. Props change : If props change, re-render happens.</p><p>3️. Context value changes: If the component consumes context → it re-renders when context updates.</p><h3>⚠️ Should You Use React.memo Everywhere?</h3><p>No. React.memo is a great tool, but <strong>not every component needs it</strong>.</p><ul><li>Use it for <strong>expensive components</strong> (large lists, complex UI)</li><li>Use it when <strong>props rarely change</strong></li><li>Avoid using it on <strong>small, cheap-to-render components</strong> or components receiving <strong>frequently changing props</strong></li></ul><p>Why?</p><ul><li><strong>React re-renders are usually cheap</strong></li><li><strong>React.memo itself adds a shallow comparison cost</strong></li></ul><p>In some cases, React.memo <strong>may not improve performance</strong> at all — so use it <strong>intentionally</strong>.</p><h3>🧠 Final Takeaways</h3><ul><li>Components re-render due to <strong>state, props, context, or parent re-render</strong>.</li><li><strong>React.memo</strong> only <strong>prevents re-render caused by parent re-render AND unchanged props</strong>.</li><li>It performs <strong>shallow comparison</strong>.</li><li>It is a <strong>performance optimization </strong>— not a mandatory feature.</li><li>Use it when there is a real performance need.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc03868beb34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Have You Ever Tried to Embed YouTube Videos in a React App?]]></title>
            <link>https://medium.com/@vihangathalangedara/have-you-ever-tried-to-embed-youtube-videos-in-a-react-app-02983df2114c?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/02983df2114c</guid>
            <category><![CDATA[iframe]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[regex]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Thu, 05 Feb 2026 17:17:01 GMT</pubDate>
            <atom:updated>2026-02-05T19:17:44.927Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yjK8Vk9TNblegYYJ_xZzg.png" /></figure><p><strong>Embedding YouTube videos</strong> in your <strong>React application</strong> is straightforward, but handling the variety of YouTube URL formats users might provide can be tricky. In this article, I’ll walk you through an approach to embedding YouTube videos, covering <strong>iframe</strong>, <strong>URL formats</strong>, <strong>regex extraction</strong>, and <strong>storing </strong>and <strong>displaying videos</strong>.</p><h4>1. <strong>How can we embed YouTube videos inside a React app? iframe</strong></h4><p>An <strong>iframe </strong>(inline frame) is an<strong> HTML element</strong> that allows you to <strong>embed another resource</strong> within your current page. It’s commonly used to <strong>display videos</strong>,<strong> maps</strong>, or <strong>other external content</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VWfZwyB20EHr0bbdyPT9GA.png" /><figcaption>Embed YouTube videos using iframe</figcaption></figure><p>The <strong>src </strong>attribute specifies the URL of the content to display. In this case, a YouTube video.</p><h4>2. What URL format does YouTube require for iframe embedding?</h4><p>To embed a YouTube video, the <strong>iframe’s src </strong>must be in the following format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*P948L-hAYpWhCGZ7dMm_ag.png" /><figcaption>URL format for iframe embedding</figcaption></figure><p>Here, VIDEO_ID is the unique identifier for the YouTube video.</p><h4>3. What happens if users provide different YouTube URL formats?</h4><p>There are different URLs and below are some mainly used formats:</p><ul><li><strong>Standard:</strong><br>https://www.youtube.com/watch?v=VIDEO_ID</li><li><strong>Shortened:</strong><br>https://youtu.be/VIDEO_ID</li><li><strong>Embed:</strong><br>https://www.youtube.com/embed/VIDEO_ID</li></ul><p>All these formats contain the <strong>same video ID</strong>, but in different places. To solve this problem we can extract the video ID from each URL.</p><h4>4. How can we extract the video ID from these different formats ?: Using Regex</h4><p>We can use a<strong> regular expression </strong>to extract the <strong>video ID</strong> from any supported URL. Here’s a sample regex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGLNVNJRdWoKK8PK8xEiKA.png" /><figcaption>Extract the video ID from different formats using regex</figcaption></figure><h4>5. What should we store in database?</h4><p>Instead of storing the full URL, it’s best to store only the<strong> video ID </strong>since we have to handle URLs with different formats and this makes it easy to generate the correct embed URL later.</p><h4>6. Retrieving the Video ID and Creating the iframe src dynamically</h4><p>When displaying the video, retrieve the <strong>video ID </strong>from your database and construct the<strong> embed URL </strong>for the iframe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlGK8RYYhurCpSvtrztl_A.png" /><figcaption>Retrieving the Video ID and Creating the iframe src</figcaption></figure><h4>7. <strong>How does the complete flow work from user input to video display?</strong></h4><ol><li><strong>User submits a YouTube link.</strong></li><li><strong>Backend extracts the video ID using regex and stores it in the database.</strong></li><li><strong>Frontend retrieves the video ID and embeds it using an iframe.</strong></li></ol><p>This approach ensures your app can handle various YouTube link formats and always displays videos correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sQTRdFqIZET18ocGCgSulQ.png" /><figcaption>Complete flow work from user input to video display</figcaption></figure><h4>8. Conclusion</h4><p>Using <strong>iframes </strong>to <strong>embed YouTube videos</strong> is the industry-standard, recommended by YouTube itself. By extracting and storing only the video ID, you keep your data clean and app flexible. With a simple regex, you can support multiple link formats and provide a seamless experience for your users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02983df2114c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filtering and Grouping in SQL: Using WHERE with GROUP BY]]></title>
            <link>https://medium.com/@vihangathalangedara/filtering-and-grouping-in-sql-using-where-with-group-by-a286a71e9bfb?source=rss-1fdea08bfb8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a286a71e9bfb</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[sql-queries]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Vihanga Thalangedara]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 17:36:47 GMT</pubDate>
            <atom:updated>2026-02-04T17:36:47.131Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lb4t_VIPH3wW2KBG_GM89A.png" /></figure><p>When working with SQL, two of the most commonly used clauses are <strong>WHERE</strong> and <strong>GROUP BY</strong>. Understanding</p><p>In this article, we’ll break down <strong>how </strong><strong>WHERE and </strong><strong>GROUP BY work together</strong>, and how to use <strong>HAVING </strong>to filter aggregated groups.</p><h4>1. WHERE vs HAVING</h4><ul><li><strong>WHERE</strong> filters <strong>rows before grouping</strong>.</li><li><strong>HAVING</strong> filters <strong>groups after aggregation</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*Fwe73BQiWrkMW-yJ5b95jQ.png" /><figcaption>Where and Having</figcaption></figure><h4>2. Example</h4><p>Suppose we have a Users table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*A4rW7rdT4ViVqgvhzsPwIw.png" /><figcaption>Table Users</figcaption></figure><p><strong>Task:</strong> Find <strong>duplicate first + last name</strong> combinations <strong>only for users in the US.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*bG144e0O8oqduew1SFnPIg.png" /><figcaption>SQL query</figcaption></figure><p><strong>Step 1: </strong>Apply WHERE country=&#39;US&#39; — <strong>filters the rows</strong> to include only those where the country is US.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*lQhqBpGFepNe_AMstI4Ytw.png" /><figcaption>Results after applying “where country =’US’”</figcaption></figure><p><strong>Step 2: </strong>GROUP BY first_name, last_name — <strong>groups these filtered rows</strong> by the combination of first_name and last_name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*jvcC0_F0aa4Pz6tJa-0ysw.png" /><figcaption>Results after applying “group by first_name and las_name”</figcaption></figure><p><strong>Step 3:</strong>COUNT(*) — counts how many rows are in each group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*xr73NT-tgqcxBKKh1SiSHA.png" /></figure><p><strong>Step 4: </strong>HAVING COUNT(*) &gt; 1 — keeps only groups with more than 1 row (the duplicates)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*Pyoynz-y47mQV9SnMDNNiw.png" /></figure><h4><strong>Summary</strong></h4><ul><li><strong>First filter rows by WHERE, then group those rows</strong>.</li><li>WHERE filters <strong>rows before grouping</strong>.</li><li>GROUP BY creates <strong>groups from filtered rows</strong>.</li><li>HAVING filters <strong>groups after aggregation</strong>.</li><li>You <strong>cannot</strong> use WHERE with aggregate functions like COUNT(); use HAVING instead.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a286a71e9bfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>