<?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 Imonhossain on Medium]]></title>
        <description><![CDATA[Stories by Imonhossain on Medium]]></description>
        <link>https://medium.com/@imonhossain02_4840?source=rss-ace29c6240e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lhDiUIXDm-jhN5o3</url>
            <title>Stories by Imonhossain on Medium</title>
            <link>https://medium.com/@imonhossain02_4840?source=rss-ace29c6240e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:37:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imonhossain02_4840/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[Monorepo vs Monolithic vs Multi-Repo: Choosing the Right Approach for Front-End Development.]]></title>
            <link>https://medium.com/@imonhossain02_4840/monorepo-vs-monolithic-vs-multi-repo-choosing-the-right-approach-for-front-end-development-c7dae105bd4b?source=rss-ace29c6240e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7dae105bd4b</guid>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[react-microfrontend]]></category>
            <category><![CDATA[frontend-architecture]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[front-end-frameworks]]></category>
            <dc:creator><![CDATA[Imonhossain]]></dc:creator>
            <pubDate>Sun, 05 Jan 2025 16:04:04 GMT</pubDate>
            <atom:updated>2025-01-05T16:08:00.147Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgnjS8VSGja34JqEcN9o0w.jpeg" /></figure><h3>1. Monolithic Front-End</h3><h3>What It Looks Like</h3><ul><li>In a <strong>monolithic</strong> application, the front-end code (HTML, CSS, JavaScript/TypeScript, React/Vue/Angular, etc.) typically lives in <strong>one large project</strong> alongside the back-end code.</li><li>You have a single folder structure like src/, which might contain both server-side code and client-side code.</li></ul><h3>Characteristics</h3><ol><li><strong>Single Build Process</strong>: Build scripts or bundlers (Webpack, Vite, Parcel, etc.) run once and generate the final assets.</li><li><strong>Shared Environment</strong>: The UI code is intimately tied to the backend environment (framework routes, server-side rendering, etc.).</li><li><strong>One Repository, One Project</strong>: Typically a single package.json (if Node-based) and a single pipeline for CI/CD.</li></ol><h3>Advantages</h3><ul><li><strong>Simple local setup</strong>: Cloning one repo gives you the entire system; one command to run the app locally.</li><li><strong>Straightforward updates</strong>: You don’t have to worry about syncing versions across multiple repositories.</li><li><strong>Easier for smaller teams</strong>: Rapid iteration because all front-end modules are in the same place.</li></ul><h3>Disadvantages</h3><ul><li><strong>Tightly Coupled Deployments</strong>: Even small front-end tweaks require redeploying the entire backend.</li><li><strong>Codebase Bloat</strong>: As the project grows, front-end code can become large and entangled with server logic.</li><li><strong>Harder to Scale</strong>: Splitting out certain UI features or micro-frontends later can be challenging.</li></ul><h3>2. Monorepo Front-End</h3><p>A <strong>monorepo</strong> refers to having multiple packages, projects, or apps in <strong>one version-controlled repository</strong>. from a front-end perspective it often looks like:</p><ul><li><strong>Multiple front-end applications</strong> (for example, a main web app, an admin dashboard, a marketing site).</li><li><strong>Shared libraries</strong> (like a design system, shared UI components, or a utility library).</li><li>All of these sub-projects exist in a single repository, often managed with tools like <strong>Nx</strong>, <strong>Lerna</strong>, <strong>Turborepo</strong>, or <strong>Bazel</strong> to handle shared dependencies, build scripts, and versioning strategies.</li></ul><h3>Characteristics</h3><ol><li><strong>Shared Codebase, Multiple Packages</strong>: You might have apps/ and libs/ folders, each containing separate front-end projects or libraries.</li><li><strong>Atomic Changes</strong>: You can update a shared component library and all consuming apps in the same commit/PR.</li><li><strong>Unified Tooling</strong>: Linting, testing, formatting, and release processes can be standardized and run consistently across all front-end projects.</li></ol><h3>Example</h3><p>A large React organization that uses <strong>Nx</strong> to manage:</p><ul><li>apps/website (the main product UI)</li><li>apps/admin (the admin dashboard)</li><li>libs/ui-components (shared React components for branding)</li><li>libs/utils (shared utility functions)</li></ul><p>All code is in one Git repository, but each app or library is its own discrete “package.”</p><h3>Advantages</h3><ul><li><strong>Easy Code Sharing</strong>: Shared UI components, design systems, or utility modules live in one place. Updates can be tested and merged in a single operation.</li><li><strong>Consistent Developer Experience</strong>: Same version of React, same ESLint config, same test runner, etc. for all sub-projects.</li><li><strong>Single Source of Truth</strong>: It’s harder for teams to accidentally fork or drift in library versions because everything is in one repo.</li></ul><h3>Disadvantages</h3><ul><li><strong>Repository Size &amp; Complexity</strong>: The repo can grow large, and build times can become lengthy (though tools like Nx cache and incremental builds help).</li><li><strong>Permission Management</strong>: If you need strict access control for certain apps or libraries, a single repo can complicate that.</li></ul><h3>3. Multi-Repo Front-End</h3><p>In a <strong>multi-repo</strong> (or “poly-repo”) approach, each front-end application or library has <strong>its own separate repository</strong>. This is common in organizations that have:</p><ul><li>Independent front-end “micro-frontend” teams.</li><li>Separate marketing site(s), documentation site(s), main product UI, etc.</li><li>Shared libraries or design systems typically as dedicated repos published to a registry (e.g., npm).</li></ul><h3>Characteristics</h3><ol><li><strong>Independent Repos</strong>: Each front-end app is self-contained with its own package.json, build scripts, and CI/CD pipeline.</li><li><strong>Versioned and Deployed Separately</strong>: Each repo can release updates independently of others.</li><li><strong>Distributed Ownership</strong>: Different teams can own different front-end repos and manage them without stepping on each other’s toes.</li></ol><h3>Example</h3><ul><li>company-webapp repo (the main React or Angular product)</li><li>company-marketing-site repo (static site or Next.js marketing)</li><li>company-design-system repo (a published npm package containing shared UI components)</li></ul><p>Whenever the design system changes, it publishes a new version to npm, and the other front-end apps update their package.json references.</p><h3>Advantages</h3><ul><li><strong>Independence &amp; Autonomy</strong>: Each app or library can evolve, deploy, and fail independently. No single repo ties all teams together.</li><li><strong>Security: </strong>If some repos are private or have restricted access, it’s easier to isolate them from others.</li></ul><h3>Disadvantages</h3><ul><li><strong>Dependency Drift</strong>: Shared libraries can get out of sync. Each front-end app might be using different (sometimes incompatible) versions.</li><li><strong>Coordinating Cross-Cutting Changes</strong>: Updating a shared component across multiple apps means multiple PRs in multiple repos.</li><li><strong>Duplicate Setup</strong>: DevOps or tooling might have to be replicated in each repo (like lint configs, test configs, etc.), unless you have an internal “template” approach.</li><li><strong>Productivity</strong>: If product is growing and rapid development it will kill team productivity.</li></ul><h3>When to Choose Which?</h3><h3>Monolithic Front-End</h3><ul><li><strong>Early-stage or simple products</strong>: A single web app that’s closely coupled , easy to set up and deploy quickly.</li><li><strong>Minimal front-end complexity</strong>: If your UI is fairly small or if you don’t anticipate multiple UIs or shared libs soon.</li></ul><h3>Monorepo Front-End</h3><ul><li><strong>Multiple related front-end apps</strong> that share a lot of code (e.g., a design system or component library) and you want to manage them in one place.</li><li><strong>Frequent cross-cutting updates</strong> across apps or libraries (like a big style redesign or a brand change).</li><li><strong>Desire for a consistent developer experience</strong>: One place to enforce linting, testing, versioning, etc.</li></ul><h3>Multi-Repo Front-End</h3><ul><li><strong>Independent front-end </strong>each owned by different teams with separate deployment schedules.</li><li><strong>Large org, strict boundaries</strong>: Different departments or domains require separate repos for security or organizational reasons.</li><li><strong>Stable shared libraries</strong>: If your design system or shared components are fairly stable, publishing them for separate repos may not be a big overhead.</li></ul><h3>Key Takeaways</h3><ul><li><strong>Monolithic</strong>: One large project, simpler at first, but can become unwieldy as front-end code grows.</li><li><strong>Monorepo</strong>: Multiple front-end apps/libraries in one repo for easy collaboration and shared tooling. Great if you frequently share UI components or make cross-cutting updates.</li></ul><p><strong>Multi-Repo</strong>: Each app or library in its own repo for maximum independence. Requires more coordination for shared components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7dae105bd4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Diffing and Reconciliation]]></title>
            <link>https://medium.com/@imonhossain02_4840/react-diffing-and-reconciliation-8922a144ab70?source=rss-ace29c6240e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8922a144ab70</guid>
            <category><![CDATA[diffing-algorithm]]></category>
            <category><![CDATA[reconciliation]]></category>
            <category><![CDATA[virtual-dom]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-key]]></category>
            <dc:creator><![CDATA[Imonhossain]]></dc:creator>
            <pubDate>Sun, 15 Dec 2024 09:43:16 GMT</pubDate>
            <atom:updated>2024-12-15T09:43:16.876Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Diffing and reconciliation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4NC9brrK7bO1Trk46zguLQ.jpeg" /></figure><p>Today, I’ll explain <strong>diffing</strong> and <strong>reconciliation</strong> in React. First, let’s look at a few examples to understand these concepts.</p><h4>Example 1: Losing Input State</h4><pre>export function App() {<br> const [displayType, setDisplayType] = useState(&#39;game&#39;);<br> return (<br>   &lt;div className=&quot;App&quot;&gt;<br>     &lt;CheckBox displayType={displayType} setDisplayType={setDisplayType} /&gt;<br>     {displayType === &#39;game&#39; ? &lt;input placeholder=&quot;Game&quot; /&gt; : &lt;DisplayText /&gt;}<br>   &lt;/div&gt;<br> );<br>}<br><br><br>function CheckBox({displayType, setDisplayType}: {displayType: string, setDisplayType: React.Dispatch&lt;React.SetStateAction&lt;string&gt;&gt;<br>} ){<br> return (<br>   &lt;&gt;<br>   &lt;br /&gt;<br>     &lt;label&gt;<br>     &lt;input type=&quot;checkbox&quot; checked={displayType === &#39;&#39;} onChange={() =&gt; setDisplayType(displayType===&#39;game&#39;? &#39;game-center&#39;: &#39;game&#39;)} /&gt;<br>     Check If you want to show Game.<br>   &lt;/label&gt;<br> &lt;/&gt;<br> )<br>}</pre><p><strong>Expected Behavior</strong>:</p><ul><li>By default, displayType is ‘game’. So, the input field appears.</li><li>If you type something into the input and toggle the checkbox, displayType becomes ‘game-center’, the input disappears, and the DisplayText component appears.</li><li>If you toggle back to ‘game’, the input reappears <strong>empty</strong>, losing whatever you typed.</li></ul><p><strong>Why is the input empty here?<br></strong>This happens because React unmounts the input when switching between ‘game’ and ‘game-center’. The input has its own internal state, which is lost when the component is unmounted.</p><h4>Example 2: Keeping Input State</h4><pre>export function App() {<br> const [displayType, setDisplayType] = useState(&#39;game&#39;);<br> return (<br>   &lt;div className=&quot;App&quot;&gt;<br>     &lt;CheckBox displayType={displayType} setDisplayType={setDisplayType} /&gt;<br>     {displayType === &#39;game&#39; ? &lt;input placeholder=&quot;Game&quot; /&gt;: &lt;input placeholder=&quot;Game Center&quot; /&gt;}<br>   &lt;/div&gt;<br> );<br>}</pre><p><strong>What’s Changed?</strong></p><pre>{displayType === &#39;game&#39; ? &lt;input placeholder=&quot;Game&quot; /&gt; : &lt;input placeholder=&quot;Game Center&quot; /&gt;}</pre><p>Here, both conditions render an input field</p><p><strong>Expected Behavior</strong>:<br>If you type in the first input (Game) and toggle the checkbox, the second input (Game Center) appears. Surprisingly, the typed text <strong>does not disappear</strong>.</p><p><strong>Why?<br></strong>React notices that both inputs have the same element type (input). Instead of unmounting and remounting, it just updates the attributes of the existing element.</p><h4>Why the Difference Between Example 1 and Example 2?</h4><ul><li>In <strong>Example 1</strong>, the elements are different: input vs. DisplayText. React unmounts the input because it sees them as completely different components.</li><li>In <strong>Example 2</strong>, the elements are the same type (input). React updates the existing element instead of unmounting it.</li></ul><p>In<strong> Example 1 </strong>before render and after render virtual Dom was</p><pre>// When displayType = ‘game’<br>{<br> type: input,<br> ...rest of the property<br>}<br>// When displayType = ‘game-center’<br>{<br> type: DisplayText<br>  ...rest of the property<br>}</pre><p>But in <strong>Example 2</strong> before render and after render virtual Dom was</p><pre>// When displayType = ‘game’<br>{<br> type: input,<br> ...rest of the property<br>}<br>// When displayType = ‘game-center’<br>{<br> type: input<br>  ...rest of the property<br>}</pre><h4>Fixing State Loss (Example 3)</h4><p>To reset the input state when switching between ‘game’ and ‘game-center’, use a unique key for each input:</p><pre>{displayType === &#39;game&#39;? &lt;input placeholder=&quot;Game&quot; key=&quot;game&quot; /&gt;: &lt;input placeholder=&quot;Game Center&quot; key=&quot;game-center&quot; /&gt;}</pre><p><strong>Why Does This Work?</strong></p><ul><li>React treats elements with different keys as separate components.</li><li>This forces React to unmount the old input and mount a new one when switching between states.</li></ul><h4>Why Avoid Components Inside Components?</h4><p><strong>Example 4: A Common Mistake</strong></p><pre>export function App() {<br> const [displayType, setDisplayType] = useState(&#39;game&#39;);<br> const CheckboxComponent = () =&gt;{<br>   return &lt;CheckBox displayType={displayType} setDisplayType={setDisplayType}  /&gt;;<br> }<br> return (<br>   &lt;div className=&quot;App&quot;&gt;<br>     &lt;CheckboxComponent  /&gt;<br>     {displayType === &#39;game&#39; ? &lt;input placeholder=&quot;Game&quot;/&gt;: &lt;input placeholder=&quot;Game Center&quot;/&gt;}<br>   &lt;/div&gt;<br> );<br>}</pre><p><strong>Why Is This Bad?</strong></p><ul><li>The CheckboxComponent is recreated on every render.</li><li>React thinks it’s a new component, so it unmounts and remounts it every time, causing unnecessary re-renders and performance issues.</li></ul><p>Answer: from reconciliation object perspective its represent in virtual dom is look like</p><pre>{<br> type: CheckboxComponent<br>}</pre><p>It is a plain object which has a type property and its return a function. And this component will re-create in every rerender. So react try to compare both in every re-render cycle but type: CheckboxComponent reference will be change in every re-render because as javascript perspective we know</p><pre>const a = () =&gt; {};<br>const b = () =&gt; {};<br>a === b; // always false</pre><p>Now you can think what’s the problem: CheckboxComponent will unmount and mount in every re-rendering process of the App. It’s a terrible performance issue. Re-mounting will take at least two times longer than re-render. So please don’t write a component inside another component.</p><h3>Why Do We Need Unique Keys in React Maps?</h3><p>We have some misconception about react key. I noticed some developers say we have to pass an index because of performance , yeah it’s partially true. But the index is more than that. Let’s go deeper.</p><p>We already know React uses a process called reconciliation to update the DOM. when any state of a component changes, react compares the updated changes with previous change in virtual dom. By identifying changes, React updates only the necessary parts of the actual DOM.</p><p>When rendering lists, React uses <strong>keys</strong> to identify each element. Without unique keys, React cannot correctly match virtual DOM elements with their real DOM counterparts, leading to errors and unexpected behavior.</p><p>Let’s go with an example.</p><h3>Example 1: No Key Provided</h3><pre>const list = [<br> {<br>   name: &#39;Apple&#39;,<br>   id: &#39;1&#39;<br> },<br> {<br>   name: &#39;Orange&#39;,<br>   id: &#39;2&#39;<br> },<br> {<br>   name: &#39;Banana&#39;,<br>   id: &#39;3&#39;<br> },<br> {<br>   name: &#39;Lemon&#39;,<br>   id: &#39;4&#39;<br> },<br>]<br>export function App() {<br> const [sortedList, setSortedList] = useState(list);<br> const [isAscending, setIsAscending] = useState(true);<br> const toggleSort = () =&gt; {<br>   const sorted = [...sortedList].sort((a, b) =&gt; {<br>     if (isAscending) {<br>       return a.name.localeCompare(b.name);<br>     } else {<br>       return b.name.localeCompare(a.name);<br>     }<br>   });<br>   setSortedList(sorted);<br>   setIsAscending(!isAscending);<br> };<br> return (<br>   &lt;div className=&quot;App&quot;&gt;<br>     &lt;button type=&quot;button&quot; onClick={toggleSort}&gt;<br>       Toggle<br>     &lt;/button&gt;<br>    {<br>     sortedList?.map((item, index) =&gt;<br>       &lt;div&gt;<br>          {item.name}<br>          &lt;input type=&quot;text&quot; /&gt;<br>       &lt;/div&gt;<br>     )<br>    }<br>   &lt;/div&gt;<br> );<br>}</pre><p>In this example I displayed the fruit’s name and beside that I added an input field. And added a Toggle button to toggle the list ascending and descending order.</p><p>What is the expected result of this component? Obviously we will get a console error for no passing key. And the main problem is: Input field states(value after typing) are not preserved after toggling the sort.</p><h4>Behavior</h4><p>In this code, no <strong>key</strong> prop is provided. When the <strong>toggleSort</strong> function reorders the list, React struggles to differentiate between components. As a result:</p><ul><li>Input field states are not preserved after toggling the sort.</li><li>React may unnecessarily destroy and recreate DOM elements, reducing performance.</li></ul><p><strong>Example 2: Index as the Key</strong></p><pre>sortedList?.map((item, index) =&gt;<br> &lt;div key={index}&gt;<br>   {item.name}<br>   &lt;input type=&quot;text&quot; /&gt;<br> &lt;/div&gt;<br>)</pre><p>I added key={index}</p><h4>Behavior</h4><p>Here, the <strong>index</strong> is used as the <strong>key</strong>. While this solves the performance issue, it introduces subtle bugs:</p><ul><li>If the order of elements changes, React will associate the wrong DOM nodes with the updated data.</li><li>Input field states are still lost because React reuses DOM elements based on their original positions rather than their current data.</li></ul><h3>Example 3: Unique Identifier as the Key</h3><pre>sortedList?.map((item, index) =&gt;<br> &lt;div key={item.id}&gt;<br>   {item.name}<br>   &lt;input type=&quot;text&quot; /&gt;<br> &lt;/div&gt;<br>)</pre><p>I added unique identifier as key <strong>&lt;div key={item.id}&gt;</strong></p><h4>Behavior</h4><p>In this example, each item has a unique id used as the key. This ensures:</p><ul><li>React correctly matches virtual DOM elements with real DOM elements, even if their order changes.</li><li>Input field states are preserved because React identifies each component by its id, not its position.</li></ul><h3>Key Takeaways</h3><ol><li>Use unique keys for lists to avoid state loss and improve performance.</li><li>Avoid creating components inside components to prevent unnecessary re-renders.</li><li>Understand how React handles elements during reconciliation to predict state behavior.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8922a144ab70" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>