<?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 Hridoy Shil on Medium]]></title>
        <description><![CDATA[Stories by Hridoy Shil on Medium]]></description>
        <link>https://medium.com/@hridoycodev?source=rss-c82e288b5744------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HXS0LhhUvK3d9Jy8</url>
            <title>Stories by Hridoy Shil on Medium</title>
            <link>https://medium.com/@hridoycodev?source=rss-c82e288b5744------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 15:45:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hridoycodev/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[Next App Hybrid Folder Architecture]]></title>
            <link>https://medium.com/@hridoycodev/next-app-hybrid-folder-architecture-bd4f0564e4b8?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd4f0564e4b8</guid>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Fri, 03 Apr 2026 05:28:03 GMT</pubDate>
            <atom:updated>2026-04-03T05:28:03.090Z</atom:updated>
            <content:encoded><![CDATA[<p>The complete architecture for mid size app:</p><pre>├── app/<br>│   ├── (auth)/<br>│   │   ├── login/<br>│   │   │   └── page.tsx<br>│   │   │   └── _components/<br>│   │   ├── register/<br>│   │   │   └── page.tsx<br>│   │   │   └── _components/<br>│   │   ├── forgot-password/<br>│   │   │   └── page.tsx<br>│   │   │   └── _components/<br>│   │   ├── verify-otp/<br>│   │   │   └── page.tsx<br>│   │   │   └── _components/<br>│   │   ├── set-password/<br>│   │   │   └── page.tsx<br>│   │   │   └── _components/<br>│   │   └── layout.tsx<br>│   │<br>│   ├── (dashboard)/<br>│   │   ├── page.tsx                        ← /dashboard<br>│   │   ├── layout.tsx<br>│   │   │<br>│   │   ├── contractors/<br>│   │   │   ├── page.tsx<br>│   │   │   ├── _components/<br>│   │   │   │   └── ContractorsTable.tsx<br>│   │   │   └── [id]/<br>│   │   │       ├── page.tsx<br>│   │   │       └── _components/<br>│   │   │           ├── ContractorProfile.tsx<br>│   │   │           ├── ContractorStats.tsx<br>│   │   │           └── ContractorOrderList.tsx<br>│   │   │<br>│   │   ├── runners/<br>│   │   │   ├── page.tsx<br>│   │   │   ├── _components/<br>│   │   │   │   └── RunnersList.tsx<br>│   │   │   └── [id]/<br>│   │   │       ├── page.tsx<br>│   │   │       └── _components/<br>│   │   │           ├── RunnerProfile.tsx<br>│   │   │           ├── RunnerStats.tsx<br>│   │   │           └── RunnerJobList.tsx<br>│   │   │<br>│   │   ├── orders/<br>│   │   │   ├── page.tsx<br>│   │   │   └── _components/<br>│   │   │       ├── OrderListTable.tsx<br>│   │   │       └── OrderStats.tsx<br>│   │   │<br>│   │   ├── payments/<br>│   │   │   ├── page.tsx<br>│   │   │   └── _components/<br>│   │   │       └── PaymentsTable.tsx<br>│   │   │<br>│   │   ├── live-operations/<br>│   │   │   ├── page.tsx<br>│   │   │   └── _components/<br>│   │   │       └── LiveMap.tsx<br>│   │   │<br>│   │   ├── supplyhouse/<br>│   │   │   ├── page.tsx<br>│   │   │   └── _components/<br>│   │   │       └── SupplyhouseTable.tsx<br>│   │   │<br>│   │   └── settings/<br>│   │       ├── page.tsx<br>│   │       └── _components/<br>│   │           ├── SettingsSidebar.tsx<br>│   │           ├── CompanyInfo.tsx<br>│   │           ├── DeliveryFeeConfig.tsx<br>│   │           └── Password.tsx<br>│   │<br>│   ├── globals.css<br>│   ├── layout.tsx<br>│   └── favicon.ico<br>│<br>│<br>├── components/<br>│   ├── ui/                                 ← shadcn primitives, never touch<br>│   │   ├── button.tsx<br>│   │   ├── input.tsx<br>│   │   ├── select.tsx<br>│   │   ├── card.tsx<br>│   │   ├── table.tsx<br>│   │   ├── avatar.tsx<br>│   │   ├── checkbox.tsx<br>│   │   ├── skeleton.tsx<br>│   │   ├── switch.tsx<br>│   │   ├── label.tsx<br>│   │   ├── chart.tsx<br>│   │   └── input-otp.tsx<br>│   │<br>│   ├── common/                             ← layout, used on every page<br>│   │   ├── DashboardLayout.tsx<br>│   │   ├── Sidebar.tsx<br>│   │   └── Topbar.tsx<br>│   │<br>│   └── reusable/                           ← shared across 2+ pages<br>│       ├── DataTable.tsx<br>│       ├── StatusBadge.tsx<br>│       ├── StatsCard.tsx<br>│       ├── CustomButton.tsx<br>│       ├── CustomSelect.tsx<br>│       ├── FormField.tsx<br>│       ├── ReusablePagination.tsx<br>│       └── TableSkeleton.tsx<br>│<br>│<br>├── services/                               ← raw axios calls, no tanstack here<br>│   ├── authService.ts<br>│   ├── contractorsService.ts<br>│   ├── runnersService.ts<br>│   ├── ordersService.ts<br>│   ├── paymentsService.ts<br>│   ├── liveOperationsService.ts<br>│   ├── supplyHouseService.ts<br>│   └── settingsService.ts<br>│<br>│<br>├── hooks/                                  ← tanstack query hooks only<br>│   ├── useAuth.ts<br>│   ├── useContractors.ts<br>│   ├── useRunners.ts<br>│   ├── useOrders.ts<br>│   ├── usePayments.ts<br>│   ├── useLiveOperations.ts<br>│   ├── useSupplyHouse.ts<br>│   └── useSettings.ts<br>│<br>│<br>├── types/<br>│   ├── auth.types.ts<br>│   ├── contractor.types.ts<br>│   ├── runner.types.ts<br>│   ├── order.types.ts<br>│   ├── payment.types.ts<br>│   ├── settings.types.ts<br>│   └── common.types.ts                     ← ApiResponse, PaginatedResponse etc<br>│<br>│<br>├── constants/<br>│   ├── routes.ts                           ← all route strings<br>│   ├── queryKeys.ts                        ← all tanstack query keys<br>│   └── app.constants.ts                   ← misc constants<br>│<br>│<br>├── lib/<br>│   ├── axios.ts                            ← axios instance + interceptors<br>│   ├── queryClient.ts                      ← tanstack queryClient config<br>│   └── utils.ts                            ← cn() and other helpers<br>│<br>│<br>└── icons/<br>    ├── SidebarIcons.tsx<br>    ├── StatsIcon.tsx<br>    ├── CalendarIcon.tsx<br>    └── UserIcon.tsx</pre><h3>Key Files Explained</h3><p><strong>constants/queryKeys.ts</strong></p><pre>export const queryKeys = {<br>  contractors: {<br>    all: [&quot;contractors&quot;] as const,<br>    detail: (id: string) =&gt; [&quot;contractors&quot;, id] as const,<br>  },<br>  runners: {<br>    all: [&quot;runners&quot;] as const,<br>    detail: (id: string) =&gt; [&quot;runners&quot;, id] as const,<br>  },<br>  orders: {<br>    all: [&quot;orders&quot;] as const,<br>  },<br>  payments: {<br>    all: [&quot;payments&quot;] as const,<br>  },<br>}</pre><p><strong>constants/routes.ts</strong></p><pre>export const ROUTES = {<br>  login: &quot;/login&quot;,<br>  register: &quot;/register&quot;,<br>  dashboard: &quot;/&quot;,<br>  contractors: &quot;/contractors&quot;,<br>  contractorDetail: (id: string) =&gt; `/contractors/${id}`,<br>  runners: &quot;/runners&quot;,<br>  runnerDetail: (id: string) =&gt; `/runners/${id}`,<br>  orders: &quot;/orders&quot;,<br>  payments: &quot;/payments&quot;,<br>  liveOperations: &quot;/live-operations&quot;,<br>  supplyHouse: &quot;/supplyhouse&quot;,<br>  settings: &quot;/settings&quot;,<br>} as const</pre><p><strong>types/common.types.ts</strong></p><pre>export interface ApiResponse&lt;T&gt; {<br>  data: T<br>  message: string<br>  success: boolean<br>}</pre><pre>export interface PaginatedResponse&lt;T&gt; {<br>  data: T[]<br>  total: number<br>  page: number<br>  limit: number<br>}</pre><pre>export type Status = &quot;active&quot; | &quot;inactive&quot; | &quot;pending&quot; | &quot;suspended&quot;</pre><h3>The Golden Rules</h3><pre>app/          → routing and page composition only, no logic<br>_components/  → used by one page only<br>reusable/     → used by two or more pages<br>services/     → axios calls only, no tanstack<br>hooks/        → tanstack only, no axios<br>types/        → one file per domain<br>constants/    → no magic strings anywhere in the app</pre><p>This is clean, practical, and has room to grow into a full feature-based structure domain by domain if you ever need to.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd4f0564e4b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Your React Query UI Isn’t Updating (And How Query Key Factories Fix It)]]></title>
            <link>https://medium.com/@hridoycodev/why-your-react-query-ui-isnt-updating-and-how-query-key-factories-fix-it-1a1f78e4904d?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a1f78e4904d</guid>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 07:16:51 GMT</pubDate>
            <atom:updated>2026-03-08T07:17:08.083Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve worked with <strong>TanStack Query (React Query)</strong>, you’ve probably faced this situation:</p><p>You perform a mutation — maybe <strong>update a profile, suspend a user, or delete an item</strong> — but the UI doesn’t update.</p><p>You check the network tab.<br>The request succeeded.<br>The server returned the correct response.</p><p>But the UI still shows <strong>old data</strong>.</p><p>Then you refresh the page… and suddenly everything is correct.</p><p>This usually happens because of <strong>inconsistent query keys</strong>.</p><h3>How Query Keys Work</h3><p>React Query stores cached data using <strong>query keys</strong> — usually arrays that describe what data the query represents.</p><p>Example:</p><pre>[&quot;users&quot;]</pre><p>Fetching a specific user:</p><pre>[&quot;users&quot;, id]</pre><p>Fetching a filtered list:</p><pre>[&quot;users&quot;, { role: &quot;admin&quot; }]</pre><p>React Query treats these keys like <strong>hierarchical paths</strong>, and it invalidates queries using <strong>prefix matching</strong>.</p><h3>Why the UI Sometimes Doesn’t Update</h3><p>Imagine your app uses these keys:</p><pre>[&quot;creators&quot;]<br>[&quot;userDet&quot;,&quot;creators&quot;,id]<br>[&quot;users&quot;,id]<br>[&quot;userData&quot;,&quot;users&quot;]</pre><p>These keys are inconsistent.</p><p>Now suppose you run:</p><pre>queryClient.invalidateQueries({ queryKey: [&quot;creators&quot;] })</pre><p>Only queries that <strong>start with </strong><strong>&quot;creators&quot;</strong> will refetch.</p><p>So this updates:</p><pre>[&quot;creators&quot;]</pre><p>But this does <strong>not</strong>:</p><pre>[&quot;userDet&quot;,&quot;creators&quot;,id]</pre><p>Result:</p><ul><li>list page updates</li><li>detail page still shows stale data</li></ul><p>This is one of the most common <strong>React Query cache bugs</strong>.</p><h3>A Simple Fix: Use a Consistent Structure</h3><p>A better query key pattern looks like this:</p><pre>[&quot;resource&quot;]<br>[&quot;resource&quot;,&quot;list&quot;]<br>[&quot;resource&quot;,&quot;detail&quot;,id]<br>[&quot;resource&quot;,&quot;list&quot;,filters]</pre><p>Example for users:</p><pre>[&quot;users&quot;]<br>[&quot;users&quot;,&quot;list&quot;]<br>[&quot;users&quot;,&quot;detail&quot;,id]</pre><p>Fetching users:</p><pre>useQuery({<br>  queryKey: [&quot;users&quot;,&quot;list&quot;],<br>  queryFn: fetchUsers<br>})</pre><p>Fetching a single user:</p><pre>useQuery({<br>  queryKey: [&quot;users&quot;,&quot;detail&quot;,id],<br>  queryFn: () =&gt; fetchUser(id)<br>})</pre><h3>Why This Works</h3><p>Because invalidation uses <strong>prefix matching</strong>.</p><pre>queryClient.invalidateQueries({ queryKey: [&quot;users&quot;] })</pre><p>This invalidates:</p><pre>[&quot;users&quot;]<br>[&quot;users&quot;,&quot;list&quot;]<br>[&quot;users&quot;,&quot;detail&quot;,id]</pre><p>So both the <strong>list and detail pages refetch automatically</strong>, keeping the UI in sync.</p><h3>The Scalable Solution: Query Key Factory</h3><p>In large apps, writing query keys manually can still lead to mistakes.</p><p>A better pattern is a <strong>Query Key Factory</strong>.</p><p>Example:</p><pre>export const userKeys = {<br>  all: [&quot;users&quot;],<br>  lists: () =&gt; [...userKeys.all, &quot;list&quot;],<br>  list: (filters) =&gt; [...userKeys.lists(), filters],<br>  details: () =&gt; [...userKeys.all, &quot;detail&quot;],<br>  detail: (id) =&gt; [...userKeys.details(), id],<br>}</pre><p>Use it in queries:</p><pre>useQuery({<br>  queryKey: userKeys.list(filters),<br>  queryFn: fetchUsers<br>})</pre><p>And invalidate everything related to users:</p><pre>queryClient.invalidateQueries({<br>  queryKey: userKeys.all<br>})</pre><p>This keeps query keys <strong>consistent across the entire app</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a1f78e4904d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fix Hash Scroll Issues in Next.js (And When to Use <a> vs <Link>)]]></title>
            <link>https://medium.com/@hridoycodev/how-to-fix-hash-scroll-issues-in-next-js-and-when-to-use-a-vs-link-40e52912f86c?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/40e52912f86c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 03:33:19 GMT</pubDate>
            <atom:updated>2026-03-01T03:35:10.516Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0tgoMEu8oZq9mkUEQYENg.png" /></figure><p>If you’ve ever added a link like /#contact-us in a Next.js app, you might have noticed something strange:</p><ul><li>It scrolls correctly the first time.</li><li>But if you click it again, nothing happens.</li><li>Or it scrolls to the wrong position.</li></ul><p>This isn’t a bug. It’s just how browsers and Next.js routing work.</p><p>Let’s break it down simply.</p><h3>Why Hash Scroll Stops Working</h3><p>Imagine you’re already on:</p><pre>/#contact-us</pre><p>If you click the same link again, the URL doesn’t change.</p><p>Browsers only trigger scrolling when the hash changes. Since #contact-us is already active, nothing happens.</p><p>That’s expected behavior.</p><h3>The Scroll Position Problem</h3><p>Another common issue: the page scrolls, but the section appears:</p><ul><li>Hidden under a fixed navbar</li><li>Slightly too high</li><li>Slightly too low</li></ul><p>This usually happens when you have a fixed header and no scroll offset defined.</p><h3>When to Use &lt;Link&gt; vs &lt;a&gt; in Next.js</h3><p>This is where many developers get confused.</p><h3>✅ Use &lt;Link&gt; for Internal Navigation</h3><p>If you’re linking inside your Next.js app:</p><pre>import Link from &quot;next/link&quot;;</pre><pre>&lt;Link href=&quot;/#contact-us&quot;&gt;Contact Us&lt;/Link&gt;</pre><p>Use &lt;Link&gt; for:</p><ul><li>Page-to-page navigation</li><li>Hash links inside your app</li><li>Better performance (no full reload)</li></ul><h3>✅ Use &lt;a&gt; for External Links</h3><p>If the link goes outside your app:</p><pre>&lt;a href=&quot;https://example.com&quot; target=&quot;_blank&quot;&gt;<br>  External Site<br>&lt;/a&gt;</pre><p>Use &lt;a&gt; for:</p><ul><li>External websites</li><li>File downloads</li><li>Full page reload cases</li></ul><h3>The Clean Fix for Hash Scroll Issues</h3><p>The best solution doesn’t require JavaScript.</p><h3>1. Enable Smooth Scrolling</h3><p>In your global CSS:</p><pre>html {<br>  scroll-behavior: smooth;<br>}</pre><h3>2. Add Scroll Margin to the Section</h3><p>If you have a fixed navbar, add a scroll margin:</p><pre>&lt;section id=&quot;contact-us&quot; className=&quot;scroll-mt-24&quot;&gt;</pre><p>Adjust the value based on your navbar height.</p><p>This ensures the section aligns correctly when scrolled into view.</p><h3>Final Rule</h3><p>If the link stays inside your app → use &lt;Link&gt;<br>If the link leaves your app → use &lt;a&gt;</p><p>Most hash scroll issues happen because of fixed headers and browser behavior — not because something is broken.</p><p>Once you understand that, the fix is simple.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40e52912f86c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Your Tailwind Form/Div Shrinks (And How to Fix It)]]></title>
            <link>https://medium.com/@hridoycodev/why-your-tailwind-form-div-shrinks-and-how-to-fix-it-797197c189a3?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/797197c189a3</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 05:59:30 GMT</pubDate>
            <atom:updated>2026-02-18T05:59:30.135Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why Your Tailwind Form Shrinks (And How to Fix It)</h3><p>When building authentication pages in Next.js with Tailwind CSS, I ran into a frustrating issue:</p><p>My form kept shrinking.</p><p>Even though I used w-full, the form wouldn’t take the full width of its parent. It looked smaller than expected — almost like it was ignoring my width settings.</p><p>If you’ve faced something similar, this article explains exactly why it happens and how to fix it properly.</p><h3>The Problem</h3><p>Here was my layout structure:</p><pre>&lt;div className=&quot;flex flex-col items-center justify-center gap-12&quot;&gt;<br>  &lt;div className=&quot;w-full max-w-[550px] bg-[#F8F9FB] rounded-2xl p-6 sm:p-8&quot;&gt;<br>    &lt;form className=&quot;flex flex-col gap-6 w-full&quot;&gt;<br>      ...<br>    &lt;/form&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>Even though:</p><ul><li>The card had w-full</li><li>The form had w-full</li></ul><p>The form looked smaller than expected.</p><p>So I tried this:</p><pre>&lt;form className=&quot;flex flex-col gap-6 w-[502px] mx-auto&quot;&gt;</pre><p>And it “fixed” the issue.</p><p>But that was a hack — not a real solution.</p><h3>Why It Happens</h3><p>The real culprit was this:</p><pre>items-center</pre><p>In Flexbox:</p><pre>flex flex-col items-center</pre><p>means:</p><blockquote><em>All children will shrink to their content width and be horizontally centered.</em></blockquote><p>This overrides natural stretching behavior.</p><p>So even if your child has w-full, it won’t stretch the way you expect.</p><h3>The Correct Fix</h3><p>Remove items-center.</p><p>Change this:</p><pre>&lt;div className=&quot;flex flex-col items-center justify-center gap-12&quot;&gt;</pre><p>To this:</p><pre>&lt;div className=&quot;flex flex-col gap-12 w-full&quot;&gt;</pre><p>Now your child elements can stretch naturally.</p><h3>The Proper Layout Pattern</h3><p>Here’s the clean, scalable pattern for auth pages:</p><pre>&lt;div className=&quot;max-w-[1320px] mx-auto px-4 w-full py-16&quot;&gt;<br>div className=&quot;flex flex-col gap-12&quot;&gt;<br>    &lt;div className=&quot;w-full max-w-[550px] mx-auto bg-[#F8F9FB] rounded-2xl p-6 sm:p-8&quot;&gt;<br>      &lt;form className=&quot;flex flex-col gap-6 w-full&quot;&gt;<br>        ...<br>      &lt;/form&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><p>This works because:</p><ul><li>max-w-* controls width</li><li>w-full allows stretching</li><li>mx-auto centers the card</li><li>No flex alignment conflicts</li></ul><h3>Key Flexbox Rule to Remember</h3><p>If you useYour children willitems-centershrink to content widthitems-startalign leftno alignmentstretch naturally</p><p>If something looks “collapsed” in a flex column, check items-center first.</p><h3>Bonus Tip: Always Add w-full to Inputs</h3><p>Even if your form is correct, your inputs must also have:</p><pre>className=&quot;w-full&quot;</pre><p>Otherwise they shrink to their content size, making the form look broken.</p><h3>The Big Lesson</h3><p>Most layout bugs are not width problems.</p><p>They are alignment problems.</p><p>Before adding fixed widths like w-[500px], check:</p><ul><li>Are you using items-center?</li><li>Is a parent flex container controlling alignment?</li><li>Are your children allowed to stretch?</li></ul><p>Understanding Flexbox rules saves you from hacks and makes your layout scalable.</p><h3>Final Thoughts</h3><p>The “shrinking form” issue is common in Tailwind projects, especially when building centered auth layouts.</p><p>The fix isn’t adding fixed widths.</p><p>The fix is understanding Flexbox alignment behavior.</p><p>Once you internalize this, your layouts become cleaner, more responsive, and easier to maintain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=797197c189a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google OAuth CORS Error: Why It Happens and How to Fix It]]></title>
            <link>https://medium.com/@hridoycodev/google-oauth-cors-error-why-it-happens-and-how-to-fix-it-8007dbd7d22c?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/8007dbd7d22c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[google-auth]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Thu, 29 Jan 2026 12:14:37 GMT</pubDate>
            <atom:updated>2026-01-29T12:14:37.586Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google OAuth CORS Error: Why It Happens and How to Fix It</h3><p>If you’ve ever tried to integrate <strong>Google Login (OAuth 2.0)</strong> into your web app and hit a mysterious <strong>CORS error</strong>, you’re not alone. This issue is extremely common — especially for developers using React, Next.js, or any SPA.</p><p>In this post, we’ll break down:</p><ul><li>❌ What the problem is</li><li>🤯 Why the error happens</li><li>✅ The correct solution</li><li>🧠 Key lessons to avoid this in the future</li></ul><h3>The Problem</h3><p>You create a <strong>“Continue with Google”</strong> button on your website.<br>Your backend endpoint looks like this:</p><pre>GET /api/auth/google</pre><p>When you open this URL <strong>directly in the browser</strong>, everything works:</p><ul><li>Google sign-in page opens</li><li>You can authenticate successfully</li></ul><p>But when you click the <strong>Google button inside your site</strong>, you see this error in DevTools:</p><pre>CORS error<br>Blocked by CORS policy</pre><p>And in the Network tab, you notice:</p><ul><li>Request type: xhr</li><li>Status: 302 Redirect</li><li>Redirecting to: <a href="https://accounts.google.com/o/oauth2/v2/auth">https://accounts.google.com/o/oauth2/v2/auth</a></li></ul><p>Confusing, right? 🤔</p><h3>The Root Cause (Why This Happens)</h3><p>The issue is <strong>not</strong> Google.<br>The issue is <strong>how OAuth is being triggered</strong>.</p><h3>❌ The Wrong Way (What Causes the Error)</h3><p>Many developers do this:</p><pre>fetch(&#39;/api/auth/google&#39;);</pre><p>or</p><pre>axios.get(&#39;/api/auth/google&#39;);</pre><p>This sends an <strong>AJAX (XHR)</strong> request.</p><p>Your backend then responds with:</p><pre>302 → Redirect to Google OAuth URL</pre><p>At this point, the browser tries to follow the redirect <strong>inside an XHR request</strong>.</p><p>🚫 <strong>Google OAuth does NOT allow CORS</strong><br>🚫 OAuth endpoints are not meant to be called via AJAX<br>🚫 Browsers block this for security reasons</p><p>So the browser throws a <strong>CORS error</strong>, even though your backend is correct.</p><h3>Important OAuth Rule (Very Important)</h3><blockquote><strong><em>OAuth authorization endpoints must be opened via full browser navigation — NOT via fetch or axios.</em></strong></blockquote><p>This is by design and enforced by browsers.</p><h3>The Correct Solution</h3><p>Instead of making an AJAX request, you must trigger a <strong>full page redirect</strong>.</p><h3>✅ The Right Way</h3><pre>const handleGoogleLogin = () =&gt; {<br>  window.location.href = &#39;http://192.168.7.42:4002/api/auth/google&#39;;<br>};</pre><p>Or even simpler:</p><pre>&lt;a href=&quot;http://192.168.7.42:4002/api/auth/google&quot;&gt;<br>  Continue with Google<br>&lt;/a&gt;</pre><h3>Why This Works</h3><ul><li>The browser navigates normally</li><li>Backend returns 302</li><li>Browser follows redirect to Google</li><li>Google login page opens</li><li>No CORS involved at all ✅</li></ul><h3>Bonus Gotcha: Redirect URI Mismatch</h3><p>Another common issue appears after fixing CORS.</p><p>If your app runs on:</p><pre>http://192.168.7.42:4002</pre><p>But your Google OAuth redirect URI is:</p><pre>http://localhost:4002/api/auth/google/redirect</pre><p>🚨 Google will reject it.</p><h3>✅ Fix</h3><p>In <strong>Google Cloud Console → OAuth Client → Authorized redirect URIs</strong>, add <strong>both</strong>:</p><pre>http://localhost:4002/api/auth/google/redirect<br>http://192.168.7.42:4002/api/auth/google/redirect</pre><p>OAuth requires an <strong>exact match</strong>.</p><h3>Summary (TL;DR)</h3><ul><li>❌ Don’t use fetch or axios to start Google OAuth</li><li>✅ Always use a browser redirect (window.location.href or &lt;a&gt;)</li><li>🚫 Google OAuth does not support CORS</li><li>✅ Match redirect URIs exactly (IP vs localhost matters)</li></ul><h3>Final Thought</h3><p>If Google Login works in a new tab but fails inside your app,<br><strong>you’re almost certainly starting OAuth the wrong way</strong>.</p><p>Once you understand that OAuth is a <strong>navigation flow, not an API call</strong>, the problem disappears.</p><p>Happy coding 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8007dbd7d22c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing the “removeChild” DOM NotFoundError Caused by Browser Translation in Radix/shadcn/ui]]></title>
            <link>https://medium.com/@hridoycodev/fixing-the-removechild-dom-notfounderror-caused-by-browser-translation-in-radix-shadcn-ui-130690e42eb2?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/130690e42eb2</guid>
            <category><![CDATA[not-found]]></category>
            <category><![CDATA[error]]></category>
            <category><![CDATA[shadcn]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[radix]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 04:55:47 GMT</pubDate>
            <atom:updated>2026-01-22T04:55:47.154Z</atom:updated>
            <content:encoded><![CDATA[<h3>Browser Translation vs React Portals: Why shadcn/ui Overlays Break (and the Simple Fix)</h3><p>If you’ve ever translated your app using Chrome/Edge’s built-in translation and suddenly your <strong>Select</strong>, <strong>DropdownMenu</strong>, <strong>Dialog</strong>, or <strong>Popover</strong> starts throwing errors like:</p><pre>Runtime NotFoundError<br>Failed to execute &#39;removeChild&#39; on &#39;Node&#39;: The node to be removed is not a child of this node.</pre><p>…you’ve hit a nasty edge case: <strong>browser translation can mutate the DOM in ways React portals don’t expect</strong> — and shadcn/ui (via Radix UI) relies heavily on portals for overlay components.</p><p>This post breaks down what’s happening, why it happens, and the most reliable fix you can apply across your shadcn/ui components.</p><h3>What’s actually breaking?</h3><h3>Portals 101 (quick refresher)</h3><p>shadcn/ui components like:</p><ul><li>Select</li><li>DropdownMenu</li><li>Dialog / AlertDialog</li><li>Popover</li><li>Tooltip, HoverCard, ContextMenu, etc.</li></ul><p>are built on <strong>Radix UI</strong>, which renders overlays using <strong>React portals</strong>.</p><p>Portals let Radix mount overlay DOM nodes (menus, popovers, modals) somewhere like:</p><pre>&lt;body&gt;<br>  &lt;!-- ... app ... --&gt;<br>  &lt;div id=&quot;radix-portal-root&quot;&gt;<br>    &lt;!-- dropdown content, dialog content, etc. --&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;</pre><p>This is great for stacking context, z-index, and accessibility.</p><h3>Browser translation isn’t “just text”</h3><p>When you translate a page with the browser, it can:</p><ol><li>Wrap text nodes in extra elements (translation containers)</li><li>Split or move nodes</li><li>Reorder nodes to apply translated content</li></ol><p>React (and Radix) assumes it owns the DOM structure it rendered. If the browser <em>restructures</em> that DOM, then later when Radix tries to unmount or reconcile a portal, React may attempt to remove a node that has been moved or replaced — causing the infamous removeChild error.</p><h3>The most reliable fix: translate=&quot;no&quot;</h3><p>The HTML translate attribute is a hint to browsers:</p><pre>&lt;div translate=&quot;no&quot;&gt;Don’t auto-translate this subtree&lt;/div&gt;</pre><p>When applied to the <strong>right portal-related elements</strong>, it prevents the browser from “helpfully” rewriting those nodes — so portals remain stable and cleanup works normally.</p><p>The important part: you don’t need to disable translation for your whole site. You only need to protect the <strong>interactive portal subtree</strong>.</p><h3>Where to apply it (generic strategy)</h3><h3>Protect these areas (in order of importance)</h3><ol><li><strong>Portal Content / Overlay Content</strong> (most important)</li><li><strong>Trigger</strong> elements (buttons/inputs that open overlays)</li><li><strong>Item</strong> nodes (dropdown items, select items)</li><li><strong>Optional wrappers</strong> if translation still causes issues in complex layouts</li></ol><p>If you only do one thing, <strong>protect the portal content</strong>.</p><h3>A generic patch pattern for shadcn/ui wrappers</h3><p>shadcn/ui components are typically exported wrappers around Radix primitives. That makes them easy to patch once and benefit everywhere.</p><p>Here’s the reusable “pattern”:</p><pre>function Root(props: React.ComponentProps&lt;typeof Primitive.Root&gt;) {<br>  return &lt;Primitive.Root translate=&quot;no&quot; {...props} /&gt;<br>}</pre><pre>function Trigger(props: React.ComponentProps&lt;typeof Primitive.Trigger&gt;) {<br>  return &lt;Primitive.Trigger translate=&quot;no&quot; {...props} /&gt;<br>}</pre><pre>function Content(props: React.ComponentProps&lt;typeof Primitive.Content&gt;) {<br>  return (<br>    &lt;Primitive.Portal&gt;<br>      &lt;Primitive.Content translate=&quot;no&quot; {...props} /&gt;<br>    &lt;/Primitive.Portal&gt;<br>  )<br>}</pre><pre>function Item(props: React.ComponentProps&lt;typeof Primitive.Item&gt;) {<br>  return &lt;Primitive.Item translate=&quot;no&quot; {...props} /&gt;<br>}</pre><p>That’s it. It’s boring — and that’s why it works.</p><h3>Apply it to the usual suspects (generic list)</h3><p>If you’re using shadcn/ui, consider applying translate=&quot;no&quot; inside these files:</p><ul><li>components/ui/select.tsx</li><li>components/ui/dropdown-menu.tsx</li><li>components/ui/dialog.tsx</li><li>components/ui/popover.tsx</li><li>components/ui/tooltip.tsx</li><li>components/ui/context-menu.tsx</li><li>components/ui/hover-card.tsx</li><li>anything Radix-based that uses a Portal</li></ul><p>The focus should be:</p><ul><li>*.Content</li><li>*.Trigger</li><li>optionally *.Item</li></ul><h3>But… won’t this stop translation for text inside the menu?</h3><p>Yes — <strong>for that overlay subtree</strong>.</p><p>That’s the tradeoff: you’re telling the browser <em>not to mutate those nodes</em>, so translation won’t rewrite the dropdown/dialog content.</p><p>In practice, this is usually acceptable because:</p><ul><li>translation still works for the rest of the page</li><li>overlays are transient UI, not primary reading content</li><li>stability beats “translated menu labels” (especially in admin apps)</li></ul><p>If you <em>must</em> translate overlay content, you’ll likely need an <strong>in-app i18n solution</strong> (next-intl, react-intl, i18next) rather than browser translation.</p><h3>When a wrapper translate=&quot;no&quot; helps</h3><p>Sometimes browser translation breaks not only the portal content but also nearby DOM that interacts with it (labels, flex containers, etc.). In those cases, wrapping a small region can help:</p><pre>&lt;div translate=&quot;no&quot;&gt;<br>  &lt;YourSelectOrMenu /&gt;<br>&lt;/div&gt;</pre><p>Use this sparingly — keep the “no translate” zone as small as possible.</p><h3>Testing checklist</h3><p>After patching:</p><ol><li>Open the app in Chrome/Edge</li><li>Translate the page using the browser translator</li><li>Interact with:</li></ol><ul><li>Select open/close</li><li>Dropdown open/close + click items</li><li>Dialog open/close (ESC, overlay click)</li></ul><p>Confirm:</p><ul><li>no console removeChild / NotFoundError</li><li>overlays still position correctly</li><li>keyboard interactions still work</li></ul><h3>Key takeaway</h3><p>Browser translation can restructure your DOM, and <strong>React portals are extra sensitive to unexpected DOM changes</strong>. Since shadcn/ui overlays are portal-heavy, they’re a common casualty.</p><p>The fix is simple and scalable:</p><ul><li>add translate=&quot;no&quot; to <strong>portal content</strong> (first)</li><li>then to triggers/items as needed</li><li>optionally wrap local sections if the translator still breaks nearby nodes</li></ul><p>Once you patch your shadcn/ui primitives, you usually never think about it again.</p><p>If you want, paste your components/ui/* files list (or tell me which shadcn/ui components you use), and I’ll show exactly where to apply the minimal translate=&quot;no&quot; changes—without over-blocking translation across your UI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=130690e42eb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond Hardcoding: 3 Ways to Handle Dynamic Colors in React & Tailwind CSS]]></title>
            <link>https://medium.com/@hridoycodev/beyond-hardcoding-3-ways-to-handle-dynamic-colors-in-react-tailwind-css-d397fb1ef80a?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/d397fb1ef80a</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Sun, 11 Jan 2026 06:38:22 GMT</pubDate>
            <atom:updated>2026-01-11T06:38:22.833Z</atom:updated>
            <content:encoded><![CDATA[<p>As developers, we often receive beautiful UI mockups with rich, expressive color palettes. The real challenge begins when those colors are <strong>dynamic</strong>.</p><p>In a recent project — a <strong>CV optimization platform</strong> — I faced a common UI requirement: <strong>Action Cards</strong> where the border, background opacity, and icon color all changed based on the type of feedback being shown (success, warning, info, etc.).</p><p>If you’re still hardcoding hex values into components or writing long if/else blocks for styling, this guide is for you.</p><p>Below are <strong>three practical ways</strong> to handle dynamic colors in a modern <strong>React + Tailwind (TSX)</strong> codebase — ranked from simplest to most scalable.</p><h3>1. The Direct Approach: Inline Styles</h3><p>The most straightforward solution is to pass colors directly into the style attribute. This works well when color values come from an API or database and are <strong>not known at build time</strong>.</p><h3>When to use</h3><p>✔ Colors are arbitrary<br> ✔ Colors come from external data<br> ✔ One-off dynamic styling</p><pre>const ActionCard = ({ color, title }) =&gt; (<br>  &lt;div<br>    style={{<br>      borderColor: color,<br>      backgroundColor: `${color}1A`, // ~10% opacity<br>    }}<br>    className=&quot;border border-solid rounded-lg p-6&quot;<br>  &gt;<br>    &lt;h3 style={{ color }}&gt;{title}&lt;/h3&gt;<br>  &lt;/div&gt;<br>);</pre><p><strong>Quick tip:</strong><br> Appending 1A to a hex code sets roughly <strong>10% opacity</strong> using hex alpha values.</p><h3>Gotcha ⚠️</h3><p>Inline styles <strong>don’t work with Tailwind utilities</strong> like hover:, focus:, or responsive variants. This can make interactive states harder to manage.</p><h3>2. The Cleanest Alternative: CSS Variables (Custom Properties)</h3><p>This is my <strong>preferred approach</strong>.</p><p>By combining <strong>CSS variables</strong> with Tailwind’s <strong>arbitrary values</strong>, you get flexibility without sacrificing readability or maintainability.</p><p>Instead of passing multiple colors, you pass <strong>one base color</strong>, and let CSS do the rest.</p><h3>The secret weapon: color-mix</h3><p>Modern CSS supports color-mix(), which allows you to dynamically mix a color with transparency—no JavaScript required.</p><pre>const ActionCard = ({ color, title, description, icon }) =&gt; {<br>  return (<br>    &lt;div<br>      style={{ &#39;--card-color&#39;: color } as React.CSSProperties}<br>      className=&quot;<br>        border-[var(--card-color)]<br>        bg-[color-mix(in_srgb,var(--card-color),transparent_90%)]<br>        flex flex-col items-center<br>        p-8 rounded-xl border-solid<br>      &quot;<br>    &gt;<br>      &lt;div className=&quot;bg-[var(--card-color)] w-12 h-12 rounded-full flex items-center justify-center text-white&quot;&gt;<br>        {icon}<br>      &lt;/div&gt;&lt;p className=&quot;text-black font-semibold mt-4&quot;&gt;{title}&lt;/p&gt;<br>      &lt;p className=&quot;text-gray-500 text-center&quot;&gt;{description}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>};<br></pre><h3>Why this approach wins 🏆</h3><ul><li><strong>Maintainability</strong>: Define the color once, reuse it everywhere</li><li><strong>Scalability</strong>: Add hover:bg-[var(--card-color)] without extra logic</li><li><strong>Clean JSX</strong>: Styling logic stays inside Tailwind classes</li><li><strong>Design-friendly</strong>: Designers can think in “base colors,” not variants</li></ul><h3>Gotcha ⚠️</h3><p>color-mix() is supported in modern browsers. If you need to support very old browsers, consider a fallback.</p><h3>3. The Design System Approach: Theme Mapping</h3><p>If your application uses a <strong>fixed set of brand colors</strong>, theme mapping is the safest and most consistent solution.</p><p>Instead of passing raw colors, you pass a <strong>semantic theme name</strong>.</p><pre>const colorThemes = {<br>  success: {<br>    border: &#39;border-[#10B981]&#39;,<br>    bg: &#39;bg-[#10B981]/10&#39;,<br>    text: &#39;text-[#10B981]&#39;,<br>  },<br>  warning: {<br>    border: &#39;border-[#F59E0B]&#39;,<br>    bg: &#39;bg-[#F59E0B]/10&#39;,<br>    text: &#39;text-[#F59E0B]&#39;,<br>  },<br>};<br><br>const ActionCard = ({ theme, title }) =&gt; {<br>  const styles = colorThemes[theme] || colorThemes.success;<br>  return (<br>    &lt;div className={`${styles.border} ${styles.bg} border-solid p-4 rounded`}&gt;<br>      &lt;h3 className={styles.text}&gt;{title}&lt;/h3&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><h3>When this shines ✨</h3><p>✔ Strict design system<br> ✔ Brand consistency matters<br> ✔ Limited, controlled color palette</p><h3>Gotcha ⚠️</h3><p>Theme maps can become rigid if your product later supports <strong>user-defined colors</strong>.</p><h3>So… Which One Should You Choose?</h3><p><strong>Rule of thumb:</strong></p><ul><li><strong>Inline styles</strong> → Colors come from APIs or user input</li><li><strong>CSS variables</strong> → You want flexibility with clean Tailwind classes</li><li><strong>Theme mapping</strong> → You have a strong design system</li></ul><p>There’s no single “best” solution — only the one that fits your product stage.</p><h3>Final Thoughts</h3><p>Moving away from hardcoded color strings and scattered conditionals makes your UI:</p><ul><li>Easier to theme</li><li>Easier to scale</li><li>Easier to reason about</li></ul><p>Whether you adopt CSS variables or a theme map, the goal is the same: <strong>write components that adapt without becoming fragile</strong>.</p><p>If you’re building modern React UIs with Tailwind, mastering these patterns will instantly level up both your <strong>code quality</strong> and <strong>design collaboration</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d397fb1ef80a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ 7 Common Tailwind Dynamic Styling Mistakes (and How to Fix Them)]]></title>
            <link>https://medium.com/@hridoycodev/7-common-tailwind-dynamic-styling-mistakes-and-how-to-fix-them-8dbeacced006?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dbeacced006</guid>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Thu, 16 Oct 2025 08:28:01 GMT</pubDate>
            <atom:updated>2025-10-16T08:28:01.822Z</atom:updated>
            <content:encoded><![CDATA[<p>When you first start mixing <strong>React</strong> with <strong>TailwindCSS</strong>, it feels so easy — until you try to make things <em>dynamic</em>.<br> Suddenly, Tailwind throws you curveballs like:</p><blockquote><em>❌ “Why isn’t </em><em>bg-${color}-500 working?”<br> ❌ “Why doesn’t my dynamic gradient show up?”</em></blockquote><p>Don’t worry — these are super common issues.<br> Here are <strong>7 dynamic styling problems</strong> and the cleanest ways to fix them 👇</p><h3>1️⃣ Dynamic HEX Colors — Use style={{}}</h3><p>Tailwind can’t understand HEX or RGB values that come from props or APIs.</p><h3>❌ Wrong</h3><pre>&lt;div className={`bg-[${bgColor}]`} /&gt;</pre><h3>✅ Right</h3><pre>&lt;div<br>  className=&quot;rounded-xl&quot;<br>  style={{ backgroundColor: bgColor }}<br>/&gt;</pre><p>For gradients:</p><pre>&lt;div<br>  className=&quot;bg-gradient-to-r rounded-xl&quot;<br>  style={{<br>    backgroundImage: `linear-gradient(to right, ${from}, ${to})`,<br>  }}<br>&gt;&lt;/div&gt;</pre><h3>2️⃣ Dynamic Tailwind Colors — Use Object Mapping</h3><p>Tailwind must “see” all class names at build time — it can’t parse strings like bg-${color}-500.</p><h3>✅ Fix</h3><pre>const colorMap = {<br>  blue: &quot;text-blue-600 bg-blue-100&quot;,<br>  green: &quot;text-green-600 bg-green-100&quot;,<br>  red: &quot;text-red-600 bg-red-100&quot;,<br>};</pre><pre>&lt;div className={`p-4 rounded-lg ${colorMap[color]}`}&gt;<br>  This is a {color} box<br>&lt;/div&gt;</pre><h3>3️⃣ Dynamic Font Sizes</h3><h3>❌ Wrong</h3><pre>&lt;p className={`text-${size}`}&gt;Dynamic text&lt;/p&gt;</pre><h3>✅ Fix</h3><p>If size options are limited:</p><pre>const sizeMap = {<br>  sm: &quot;text-sm&quot;,<br>  md: &quot;text-base&quot;,<br>  lg: &quot;text-lg&quot;,<br>};<br>&lt;p className={sizeMap[size]}&gt;Dynamic text&lt;/p&gt;</pre><p>If numeric:</p><pre>&lt;p style={{ fontSize: `${fontSize}px` }}&gt;Dynamic text&lt;/p&gt;</pre><h3>4️⃣ Dynamic Padding or Margin</h3><h3>❌ Wrong</h3><pre>&lt;div className={`p-${padding}`}&gt;Box&lt;/div&gt;</pre><h3>✅ Fix</h3><p>Use inline styles:</p><pre>&lt;div style={{ padding: `${padding}px` }}&gt;Box&lt;/div&gt;</pre><p>Or mapping for small, medium, large:</p><pre>const paddingMap = {<br>  sm: &quot;p-2&quot;,<br>  md: &quot;p-4&quot;,<br>  lg: &quot;p-8&quot;,<br>};<br>&lt;div className={paddingMap[padding]}&gt;Box&lt;/div&gt;</pre><h3>5️⃣ Dynamic Grid Columns</h3><h3>❌ Wrong</h3><pre>&lt;div className={`grid grid-cols-${cols}`}&gt;&lt;/div&gt;</pre><h3>✅ Fix</h3><p>Use inline grid styling:</p><pre>&lt;div style={{ display: &quot;grid&quot;, gridTemplateColumns: `repeat(${cols}, 1fr)` }}&gt;<br>  {/* items */}<br>&lt;/div&gt;</pre><h3>6️⃣ Dynamic Border Radius</h3><h3>❌ Wrong</h3><pre>&lt;div className={`rounded-${radius}`}&gt;&lt;/div&gt;</pre><h3>✅ Fix</h3><pre>&lt;div style={{ borderRadius: `${radius}px` }}&gt;Rounded box&lt;/div&gt;</pre><p>Or mapping:</p><pre>const radiusMap = {<br>  sm: &quot;rounded-sm&quot;,<br>  md: &quot;rounded-md&quot;,<br>  lg: &quot;rounded-lg&quot;,<br>};<br>&lt;div className={radiusMap[radius]}&gt;Rounded box&lt;/div&gt;</pre><h3>7️⃣ Dynamic Transition Durations</h3><h3>❌ Wrong</h3><pre>&lt;div className={`duration-${speed}`}&gt;&lt;/div&gt;</pre><h3>✅ Fix</h3><pre>&lt;div style={{ transitionDuration: `${speed}ms` }}&gt;Animated box&lt;/div&gt;</pre><h3>⚡ Quick Summary</h3><p>Problem Why it breaks How to fix HEX or RGB colors Tailwind can’t detect runtime values Use inline style={{}} Tailwind color names Tailwind can’t parse dynamic strings Use object mapping Font size Dynamic class not visible Use mapping or style Padding / Margin Same issue Use mapping or style Grid columns Tailwind doesn’t generate those classes Use inline grid styles Border radius Dynamic class not found Use inline style Transition speed Dynamic value not supported Use inline style</p><h3>💬 Final Thoughts</h3><p>TailwindCSS is powerful — but it’s <strong>static-first</strong>.<br> Whenever your styles depend on <strong>runtime data</strong>, remember this simple rule:</p><blockquote><em>🎯 </em><strong><em>Tailwind = static classes.</em></strong><em><br> </em><strong><em>style={{}} = dynamic values.</em></strong></blockquote><p>If you follow that, you’ll never get stuck wondering why your colors, sizes, or grids aren’t updating again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dbeacced006" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Fixing TypeScript Icon Errors in React: React.ElementType vs React.ReactElement]]></title>
            <link>https://medium.com/@hridoycodev/fixing-typescript-icon-errors-in-react-react-elementtype-vs-react-reactelement-2abd6152f91f?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/2abd6152f91f</guid>
            <category><![CDATA[icons]]></category>
            <category><![CDATA[elements]]></category>
            <category><![CDATA[typeerror]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Thu, 16 Oct 2025 06:21:39 GMT</pubDate>
            <atom:updated>2025-10-16T06:21:39.778Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever mixed <strong>Lucide React icons</strong> with your own <strong>custom SVG components</strong>, you’ve probably seen TypeScript scream at you with an error like:</p><pre>Type &#39;typeof CalculatorIcon&#39; is not assignable to type &#39;ReactElement&#39;</pre><p>Sounds familiar?<br> Let’s break down why this happens — and how to fix it cleanly.</p><h3>💥 The Problem</h3><p>Imagine you have a list of items, each with an icon:</p><pre>import { CalculatorIcon } from &quot;lucide-react&quot;;<br>import LightIcon from &quot;@/components/icons/LightIcon&quot;;</pre><pre>interface Item {<br>  title: string;<br>  icon: React.ReactElement; // ❌ seems right… but not really<br>}</pre><pre>const items: Item[] = [<br>  { title: &quot;Calculator&quot;, icon: CalculatorIcon }, // ❌ error!<br>  { title: &quot;Light&quot;, icon: LightIcon },           // ❌ error!<br>];</pre><p>You’ll get a <strong>type error</strong>, even though both CalculatorIcon and LightIcon work perfectly in JSX.<br> Why?</p><p>Because CalculatorIcon and LightIcon are <strong>components</strong>, not <strong>rendered elements</strong>.</p><h3>🧠 Understanding What’s Going On</h3><p>In React + TypeScript, there’s a big difference between:</p><p>ConceptExampleWhat it is<strong>React component</strong>CalculatorIconA <em>function</em> that returns JSX<strong>React element</strong>&lt;CalculatorIcon /&gt;The <em>result</em> of calling that function</p><p>So, when you write icon: CalculatorIcon, you’re storing the <strong>component</strong>.<br> But your type (React.ReactElement) expects the <strong>result of rendering</strong> that component.</p><h3>✅ The Correct Fix #1 — Use React.ElementType</h3><p>If you want to store the <strong>component</strong> itself (so you can later render &lt;item.icon /&gt; dynamically):</p><pre>import { CalculatorIcon } from &quot;lucide-react&quot;;<br>import LightIcon from &quot;@/components/icons/LightIcon&quot;;</pre><pre>interface Item {<br>  title: string;<br>  icon: React.ElementType; // ✅ can hold any React component<br>}</pre><pre>const items: Item[] = [<br>  { title: &quot;Calculator&quot;, icon: CalculatorIcon },<br>  { title: &quot;Light&quot;, icon: LightIcon },<br>];</pre><pre>export default function Example() {<br>  return (<br>    &lt;div className=&quot;space-y-2&quot;&gt;<br>      {items.map((item) =&gt; (<br>        &lt;div key={item.title} className=&quot;flex items-center gap-2&quot;&gt;<br>          &lt;item.icon className=&quot;w-5 h-5 text-blue-600&quot; /&gt; {/* ✅ works perfectly */}<br>          &lt;span&gt;{item.title}&lt;/span&gt;<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>✅ Works for:</p><ul><li>Library icons (lucide-react, heroicons, etc.)</li><li>Custom icons (your own SVG components)</li></ul><h3>✅ The Alternative Fix #2 — Use React.ReactNode</h3><p>If you want to store the <strong>rendered icon</strong> instead of the component itself,<br> just pass it directly as JSX and change your type:</p><pre>interface Item {<br>  title: string;<br>  icon: React.ReactNode; // ✅ can store JSX directly<br>}</pre><pre>const items: Item[] = [<br>  { title: &quot;Calculator&quot;, icon: &lt;CalculatorIcon className=&quot;w-5 h-5 text-blue-600&quot; /&gt; },<br>  { title: &quot;Light&quot;, icon: &lt;LightIcon className=&quot;w-5 h-5 text-yellow-500&quot; /&gt; },<br>];<br>export default function Example() {<br>  return (ty<br>    &lt;div className=&quot;space-y-2&quot;&gt;<br>      {items.map((item) =&gt; (<br>        &lt;div key={item.title} className=&quot;flex items-center gap-2&quot;&gt;<br>          {item.icon} {/* ✅ just render the element */}<br>          &lt;span&gt;{item.title}&lt;/span&gt;<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>This approach is simpler when your icons don’t need dynamic props.</p><h3>⚖️ Which One Should You Use?</h3><p>Use caseRecommended TypeExampleYou want to render &lt;item.icon /&gt; dynamicallyReact.ElementTypeicon: CalculatorIconYou want to store the element directlyReact.ReactNodeicon: &lt;CalculatorIcon /&gt;You just want something that can be anything.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2abd6152f91f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Why Tailwind CSS Dynamic Classes Don’t Work]]></title>
            <link>https://medium.com/@hridoycodev/why-tailwind-css-dynamic-classes-dont-work-c0990a53a912?source=rss-c82e288b5744------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0990a53a912</guid>
            <category><![CDATA[jsx]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[tailwind]]></category>
            <dc:creator><![CDATA[Hridoy Shil]]></dc:creator>
            <pubDate>Tue, 14 Oct 2025 15:03:32 GMT</pubDate>
            <atom:updated>2025-10-14T15:06:30.007Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever written a Tailwind CSS class like</p><pre>&lt;div className={`bg-${color}-600`}&gt;&lt;/div&gt;</pre><p>and wondered why it suddenly <strong>stops working after build</strong>, you’re not alone.</p><p>This problem confuses almost every developer new to Tailwind.<br> Let’s break down what’s happening — and how to fix it — in the simplest way possible. 💡</p><h3>🧠 What’s Actually Happening</h3><p>Tailwind CSS is <strong>smart but static</strong>.<br> It scans your project files during the build process and collects <strong>all the class names</strong> it finds — <br> then it <strong>purges (removes)</strong> any unused ones to make your final CSS super small.</p><p>That’s how Tailwind keeps your site lightning-fast ⚡</p><p>The problem?<br> Tailwind can only detect <strong>static</strong> class names written directly in your code, like this:</p><pre>&lt;div class=&quot;bg-blue-600&quot;&gt;&lt;/div&gt;</pre><p>But if you use <strong>dynamic class names</strong> — such as:</p><pre>&lt;div className={`bg-${color}-600`}&gt;&lt;/div&gt;</pre><p>Tailwind has no idea what color will be at runtime.<br> It can’t guess whether it’s red, green, or blue, so it assumes you don’t use any of those classes…<br> and <strong>purges them all</strong>.</p><p>Result: your colors vanish in production 😩</p><h3>✅ The Right Way — Use a Color Map</h3><p>Instead of building class names dynamically, create a <strong>color map object</strong> that holds all the class variants.<br> This way, Tailwind sees every possible class at build time and keeps them all.</p><p>Example:1</p><pre>const colorMap = {<br> red: &quot;bg-red-600&quot;,<br> blue: &quot;bg-blue-600&quot;,<br> green: &quot;bg-green-600&quot;,<br>};<br>&lt;div className={`${colorMap[color]} w-10 h-10`}&gt;&lt;/div&gt;</pre><p>Example:2 👇</p><pre>const colorMap = {<br>  green: {<br>    text: &quot;text-green-600&quot;,<br>    button: &quot;bg-green-500 hover:bg-green-600&quot;<br>  },<br>  blue: {<br>    text: &quot;text-blue-600&quot;,<br>    button: &quot;bg-blue-500 hover:bg-blue-600&quot;<br>  },<br>};</pre><pre>export function ColorfulButton({ color }: { color: keyof typeof colorMap }) {<br>  const selectedColor =<br>    colorMap[color as keyof typeof colorMap] || colorMap.green;<br>  return (<br>    &lt;button className={`${selectedColor.button} text-white px-4 py-2 rounded`}&gt;<br>      &lt;span className={selectedColor.text}&gt;Click Me&lt;/span&gt;<br>    &lt;/button&gt;<br>  );<br>}</pre><h3>💬 Why This Works</h3><ul><li>Tailwind can now <strong>see</strong> all the classes (bg-green-500, bg-blue-500, etc.) at build time.</li><li>When you call colorMap[color], you’re only choosing one at runtime — not generating new ones.</li><li>You can safely switch styles without breaking anything.</li></ul><h3>🧰 Alternative: Use a Safelist</h3><p>If you have many possible classes and don’t want to map them manually,<br> you can tell Tailwind to <strong>keep</strong> specific classes using the safelist option in your tailwind.config.js:</p><pre>module.exports = {<br>  safelist: [<br>    &#39;bg-green-500&#39;,<br>    &#39;bg-green-600&#39;,<br>    &#39;bg-blue-500&#39;,<br>    &#39;bg-blue-600&#39;,<br>    &#39;text-green-600&#39;,<br>    &#39;text-blue-600&#39;,<br>  ],<br>};</pre><p>This ensures these classes are always included, even if Tailwind doesn’t find them directly.</p><h3>⚙️ Quick Recap</h3><p>❓ Problem ⚡ Reason ✅ Solution Dynamic class names don’t work Tailwind purges undetected classes Use mapping or safelist bg-${color}-600 fails Not recognized during build Replace with colorMap[color] Works locally but not in production Dev mode doesn’t purge CSS Production build removes them</p><h3>🚀 Final Thoughts</h3><p>Tailwind’s purge system is amazing for performance — but only if you play by its rules.<br> By using <strong>explicit color maps</strong> or <strong>safelists</strong>, you can make your UI dynamic <strong>without breaking your build</strong>.</p><p>So next time you’re tempted to write something like bg-${color}-600,<br> remember: Tailwind can’t see runtime variables — but it will happily keep any class you show it in advance. 😄</p><p><strong>💬 Have you faced this issue before?</strong><br> Share your fix or experience in the comments — and don’t forget to follow for more Tailwind tips!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0990a53a912" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>