<?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 Paulo Eder Medeiros Cardoso on Medium]]></title>
        <description><![CDATA[Stories by Paulo Eder Medeiros Cardoso on Medium]]></description>
        <link>https://medium.com/@pauloeder7?source=rss-f0cbcadb84e9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hxJXUA2BUxGStyjh3n-9BA.jpeg</url>
            <title>Stories by Paulo Eder Medeiros Cardoso on Medium</title>
            <link>https://medium.com/@pauloeder7?source=rss-f0cbcadb84e9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:53:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pauloeder7/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[Stop Thinking in Tables. Start Thinking in Graphs.]]></title>
            <link>https://medium.com/@pauloeder7/stop-thinking-in-tables-start-thinking-in-graphs-ec78d37b5ec4?source=rss-f0cbcadb84e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec78d37b5ec4</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Paulo Eder Medeiros Cardoso]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 16:59:50 GMT</pubDate>
            <atom:updated>2026-03-09T16:59:50.687Z</atom:updated>
            <content:encoded><![CDATA[<p>How to model highly connected data without melting your relational database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIbv912pZrI1t79-49j6nw.png" /></figure><h4><strong>1. The Hook</strong></h4><p>We have all faced this scenario. You are building a feature, let’s say, a Suggested Connections engine.</p><p>The logic is simple: <em>Find the friends of my friends who are not my friends yet.</em></p><p>In a traditional Relational Database (SQL), you create a users table and a user_relationships table. For one degree of separation, you write a JOIN. It runs fine. Then product management asks for <em>three</em> degrees of separation. You write a JOIN inside a JOIN inside a JOIN.</p><p>Suddenly, your query takes 5 seconds to run, your CPU spikes to 100%, and your database is screaming for help.</p><p>This is the <strong>JOIN Hell</strong>. You are trying to solve a network problem using a spreadsheet tool. There is a better way.</p><h4><strong>2. The Analogy: The Subway Map vs. The Spreadsheet</strong></h4><p>Imagine you are visiting London and need to get from Station A to Station D.</p><p>If I hand you an Excel spreadsheet listing every station and its GPS coordinates, you will be completely lost. It is the wrong mental model. But if I hand you the <strong>Subway Map</strong> , where stations are dots (Nodes) and the tracks are lines (Edges), you instantly know the route.</p><p>Relational Databases store data like spreadsheets. <strong>Graphs</strong> store data like a map. When the <em>relationship</em> between the data is just as important as the data itself, you need a Graph.</p><h4><strong>3. The Problem</strong></h4><p>Relational databases (PostgreSQL, MySQL) are amazing for structured, tabular data (like billing or inventory). But they struggle with deep traversal.</p><p>Look at this SQL example for just finding Friends of Friends:</p><pre>-- ❌ The Rigid Way (O(N^2) or worse)<br>SELECT DISTINCT fof.friend_id<br>FROM user_relationships u1<br>JOIN user_relationships fof ON u1.friend_id = fof.user_id<br>WHERE u1.user_id = &#39;paulo_id&#39; <br>AND fof.friend_id != &#39;paulo_id&#39;<br>AND fof.friend_id NOT IN (<br>    SELECT friend_id FROM user_relationships WHERE user_id = &#39;paulo_id&#39;<br>);</pre><p>It is hard to read, hard to maintain, and extremely slow at scale.</p><h4><strong>4. The Solution: The Graph Mental Model</strong> In a Graph</h4><p>Instead of scanning massive tables, we look up exactly what we need in O(1) time.</p><p>Here is how you model and solve the exact same problem in TypeScript/Node.js using a Graph structure:</p><pre>// ✅ The Graph Way (Graph Adjacency List)<br><br>class SocialGraph {<br>  // A Map where Key = User, Value = Array of Friends<br>  private adjacencyList: Map&lt;string, Set&lt;string&gt;&gt; = new Map();<br><br>  addVertex(user: string) {<br>    if (!this.adjacencyList.has(user)) {<br>      this.adjacencyList.set(user, new Set());<br>    }<br>  }<br><br>  addEdge(user1: string, user2: string) {<br>    this.adjacencyList.get(user1)?.add(user2);<br>    this.adjacencyList.get(user2)?.add(user1); // Undirected graph<br>  }<br><br>  getRecommendations(targetUser: string): string[] {<br>    const friends = this.adjacencyList.get(targetUser) || new Set();<br>    const recommendations = new Set&lt;string&gt;();<br><br>    // O(1) lookups instead of scanning tables!<br>    for (const friend of friends) {<br>      const friendsOfFriend = this.adjacencyList.get(friend) || new Set();<br>      for (const fof of friendsOfFriend) {<br>         // Add if it&#39;s not the target user and not already a direct friend<br>        if (fof !== targetUser &amp;&amp; !friends.has(fof)) {<br>          recommendations.add(fof);<br>        }<br>      }<br>    }<br>    return Array.from(recommendations);<br>  }<br>}</pre><h4><strong>5. Visual Comparison</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*mlyE5DmI0Gx0aRnhF12dRA.png" /></figure><ul><li><strong>Top (Relational):</strong> A rigid structure forcing a long, complex traversal path (O(N^2)) just to connect distant data points.</li><li><strong>Bottom (Graph):</strong> A web of nodes where querying relationships means simply “walking” the paths that already exist (O(1)).</li></ul><h4><strong>6. Why This Matters</strong></h4><p>This isn’t just theory. This is how Netflix builds its recommendation engine. This is how Google Maps calculates routes. This is how social networks scale.</p><p>You don’t always need to implement a Graph from scratch in memory. Sometimes, realizing your data is highly connected is the trigger to adopt a dedicated Graph Database (like Neo4j) or use Redis to store Adjacency Lists.</p><p><strong>7. Closing Thoughts</strong> Frameworks come and go. Libraries get deprecated. But the core principles of Computer Science, knowing which data structure to use for which problem, are timeless.</p><p>When you stop forcing every problem into a relational table, your architecture becomes faster, cleaner, and infinitely more scalable.</p><p>Are you using any Graph structures in your current backend? Let’s discuss it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec78d37b5ec4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Building God Components. Use the Compound Pattern.]]></title>
            <link>https://medium.com/@pauloeder7/stop-building-god-components-use-the-compound-pattern-0af670db94a0?source=rss-f0cbcadb84e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/0af670db94a0</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Paulo Eder Medeiros Cardoso]]></dc:creator>
            <pubDate>Thu, 29 Jan 2026 18:25:25 GMT</pubDate>
            <atom:updated>2026-01-29T18:25:25.166Z</atom:updated>
            <content:encoded><![CDATA[<p>How to design declarative, flexible React APIs using Context and Composition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mUZmF_8uV17o03s-P2Sg8w.png" /></figure><h3>The Hook</h3><p>We have all committed this crime. You create a &lt;Card /&gt; component. It starts simple. Then, a new requirement appears: <em>&quot;Can we add a subtitle?&quot;</em> You add a subtitle prop. <em>&quot;Can we add a button in the footer?&quot;</em> You add footerButtonText and onFooterClick props. <em>&quot;Can we hide the image?&quot;</em> You add a showImage boolean.</p><p>Suddenly, your component is like this:</p><pre>&lt;Card <br>  title=&quot;Hello&quot; <br>  subtitle=&quot;World&quot; <br>  image=&quot;/img.png&quot; <br>  showImage={true} <br>  footerButtonText=&quot;Click me&quot;<br>  onFooterClick={() =&gt; {}} <br>  variant=&quot;primary&quot;<br>/&gt;</pre><p>This is the <strong>Prop Explosion Problem</strong>. You created a God Component - a rigid monolith that knows too much.</p><p>There is a better way. A way that lets the developer decide how the Card looks, without you writing a single boolean.</p><h3>2. The Analogy: The Hi-Fi System</h3><p>Think of an All-in-One Boombox from the 90s. It has the CD player, speakers, and radio glued together. If you want to move the speakers further apart? You can’t. They are hardwired.</p><p>Now think of a <strong>Professional Hi-Fi System</strong>. You have a Receiver, separate Speakers, and a Turntable. You can arrange them however you want. You can stack them, spread them out, or remove one piece entirely. They work together wirelessly or via clean cables.</p><p><strong>Compound Components</strong> are the Hi-Fi System of React.</p><h3>3. The Problem</h3><p>The Monolithic approach creates rigid HTML structures.</p><pre>// The Rigid Way (Prop Drilling)<br>const Card = ({ title, image, footer, onAction }) =&gt; (<br>  &lt;div className=&quot;card&quot;&gt;<br>    {image &amp;&amp; &lt;img src={image} /&gt;}<br>    &lt;div className=&quot;content&quot;&gt;<br>       &lt;h1&gt;{title}&lt;/h1&gt;<br>       {/* You can&#39;t easily swap the order of title and footer here! */}<br>       &lt;button onClick={onAction}&gt;{footer}&lt;/button&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>);</pre><p><strong>The limitation:</strong> What if, just for one specific page, I want the Title to be above the Image? I can’t. The structure is hardcoded inside the component.</p><h3>4. The Solution: Compound Components</h3><p>We use React Context to share state implicitly between a Parent and its Children. This allows us to break the component into sub-components.</p><pre>// ✅ The &quot;Right&quot; Way (Compound Pattern)<br><br>// Create the Context<br>const CardContext = createContext(undefined);<br><br>// The Parent Component<br>const Card = ({ children, variant = &quot;default&quot; }) =&gt; {<br>  return (<br>    &lt;CardContext.Provider value={{ variant }}&gt;<br>      &lt;div className={`card-${variant}`}&gt;{children}&lt;/div&gt;<br>    &lt;/CardContext.Provider&gt;<br>  );<br>};<br><br>// The Sub-Components<br>Card.Image = ({ src }) =&gt; &lt;img src={src} className=&quot;card-img&quot; /&gt;;<br>Card.Title = ({ children }) =&gt; &lt;h3&gt;{children}&lt;/h3&gt;;<br>Card.Footer = ({ children }) =&gt; &lt;div className=&quot;card-footer&quot;&gt;{children}&lt;/div&gt;;<br><br>// Export logic<br>export default Card;</pre><h3>5. Visual Comparison</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*Nc9aEBpYkUEuAjQR2wZFhg.png" /></figure><ul><li><strong>Left (The God Component):</strong> A Rigid Metal Box bombarded by a tangled mess of props. It illustrates the trap: simple to start, but Hard to maintain and suffering from Messy data flow.</li><li><strong>Right (The Compound Pattern):</strong> A Transparent Glass Container holding modular, independent blocks (&lt;Card.Title /&gt;, &lt;Card.Image /&gt;). It highlights the real benefit: a clean, modular structure where the developer has total control over the composition.</li></ul><h3>6. Why This Matters</h3><p>Now, look at how we consume this component. It is pure poetry.</p><pre>function App() {<br>  return (<br>    // Scenario A: Standard Order<br>    &lt;Card&gt;<br>      &lt;Card.Image src=&quot;avatar.png&quot; /&gt;<br>      &lt;Card.Title&gt;User Profile&lt;/Card.Title&gt;<br>      &lt;Card.Footer&gt;<br>        &lt;Button&gt;Edit&lt;/Button&gt;<br>      &lt;/Card.Footer&gt;<br>    &lt;/Card&gt;<br><br>    // Scenario B: Total Inversion (No code changes needed)<br>    &lt;Card variant=&quot;outlined&quot;&gt;<br>      &lt;Card.Title&gt;Inverted Layout&lt;/Card.Title&gt;<br>      &lt;Card.Footer&gt;<br>         &lt;span&gt;Last updated: today&lt;/span&gt;<br>      &lt;/Card.Footer&gt;<br>      {/* Image is at the bottom now! */}<br>      &lt;Card.Image src=&quot;chart.png&quot; /&gt; <br>    &lt;/Card&gt;<br>  );<br>}</pre><p>We achieved <strong>Inversion of Control</strong>. The library author (you) defines <em>logic</em> (styles, context). The library user defines structure.</p><h3>7. Closing Thoughts</h3><p>Great architecture isn’t about adding features, it’s about removing friction.</p><p>By using Compound Components, you shift from maintaining a list of 50 props to maintaining a set of composable building blocks. This is how libraries like <strong>Radix UI</strong> and <strong>Chakra UI</strong> allow for such high customization.</p><p>This concludes our 4 part series on Advanced React Patterns. We went from Rendering Strategies to State Machines, Polymorphism, and finally, Composition.</p><p>Mastering these patterns is what truly elevates your engineering level, bridging the gap between simply making it work and building for scale</p><p>Thank you for reading along! 🚀</p><p>#ReactJS #TypeScript #CleanCode #SoftwareArchitecture #Frontend #Engineering #DesignSystems</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0af670db94a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Duplicating Components. Use React Polymorphism]]></title>
            <link>https://medium.com/@pauloeder7/stop-duplicating-components-use-react-polymorphism-fc6da7ec8a4d?source=rss-f0cbcadb84e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc6da7ec8a4d</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Paulo Eder Medeiros Cardoso]]></dc:creator>
            <pubDate>Tue, 27 Jan 2026 16:18:07 GMT</pubDate>
            <atom:updated>2026-01-27T16:18:07.481Z</atom:updated>
            <content:encoded><![CDATA[<p>How to build flexible UI systems that adapt to your needs. A guide to advanced TypeScript Generics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRWrou7xKGASjaEgzkW5AQ.png" /></figure><h3>1. The Hook</h3><p>We have all been there. You build the perfect &lt;Button /&gt; component. It has the correct padding, the hover animations, and the loading spinner. It is part of your Design System.</p><p>Then, a requirement comes in: <em>“We need this button to link to the user’s profile page.”</em></p><p>Panic sets in. You cannot put a &lt;button&gt; inside an &lt;a&gt; tag (that is invalid HTML). So, what do you do? You copy paste the styles and create a &lt;LinkButton /&gt;. Now you have two components to maintain.</p><p>It looks blameless, but you just created <strong>Technical Debt</strong>. What if we could have <em>one</em> component that can shape-shift into whatever HTML tag we need?</p><h3>2. The Analogy: The Chameleon</h3><p>Imagine a Chameleon. It is always the same animal inside, but its outer skin changes depending on the environment.</p><ul><li>On a tree? It turns green.</li><li>On a rock? It turns grey.</li></ul><p>In React, a <strong>Polymorphic Component</strong> is like a Chameleon.</p><ul><li>Need a form action? It renders as a &lt;button&gt;.</li><li>Need navigation? It renders as an &lt;a&gt;.</li><li>Need client-side routing? It renders as a Next.js &lt;Link&gt;.</li></ul><p>It is <strong>one component</strong> with multiple identities.</p><h3>3. The Problem</h3><p>Let’s look at the Naive Approach (what most developers do).</p><pre>// ❌ The Copy Paste Hell<br>// Component: For actions<br>const Button = ({ onClick, children }) =&gt; (<br>  &lt;button className=&quot;btn-primary&quot; onClick={onClick}&gt;{children}&lt;/button&gt;<br>);<br><br>// Component: For links (Duplicate styles!)<br>const LinkButton = ({ href, children }) =&gt; (<br>  &lt;a className=&quot;btn-primary&quot; href={href}&gt;{children}&lt;/a&gt;<br>);</pre><p><strong>Why this is bad:</strong></p><ol><li><strong>Duplicate Code:</strong> If you change the padding on the Button, you must remember to change it on the LinkButton.</li><li><strong>Inflexible API:</strong> What if you need it to be a &lt;span&gt; or a div later? You would need a third component.</li></ol><h3>4. The Solution: The “as” Prop</h3><p>We use a prop (usually called as or component) to tell React which tag to render. But the magic happens in <strong>TypeScript</strong>. We need to tell the compiler: <em>If I am an anchor tag, I require an href. If I am a button, I do not.</em></p><pre>// ✅ The &quot;Senior&quot; Way (Polymorphism)<br>type ButtonProps&lt;C extends React.ElementType&gt; = {<br>  as?: C;<br>  children: React.ReactNode;<br>} &amp; React.ComponentPropsWithoutRef&lt;C&gt;; // Here the magic happens<br><br>export const Button = &lt;C extends React.ElementType = &quot;button&quot;&gt;({ <br>  as, <br>  children, <br>  ...props <br>}: ButtonProps&lt;C&gt;) =&gt; {<br>  const Component = as || &quot;button&quot;;<br>  <br>  return &lt;Component className=&quot;btn-primary&quot; {...props}&gt;{children}&lt;/Component&gt;;<br>};</pre><p>This single component can now be anything, without duplicating a single line of CSS. This is exactly how libraries like <strong>MUI</strong>, <strong>Chakra UI</strong>, and <strong>Radix</strong> are built under the hood</p><h3>5. Visual Comparison (The Diagram)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSYuGD8wmUSYNebcvaeUjA.png" /></figure><ul><li><strong>Top (Rigid Components):</strong> Two separate boxes labeled “Button” and “Link”. A wall between them. If you paint one blue, the other stays red.</li><li><strong>Bottom (Polymorphic):</strong> A single box labeled “UI Element” with an input slot. You insert a “Tag” chip (button, a, span) into the slot, and the box transforms, but keeps the same paint/style.</li></ul><h3>6. Why This Matters</h3><p>The best part isn’t just code reuse, it’s <strong>Safety</strong>. TypeScript is smart enough to change the allowed props based on the as prop.</p><pre>function App() {<br>  return (<br>    &lt;div className=&quot;flex gap-4&quot;&gt;<br>      {/* Case 1: Standard Button */}<br>      {/* TS allows &#39;onClick&#39; and &#39;disabled&#39; */}<br>      &lt;Button onClick={() =&gt; console.log(&quot;Saved!&quot;)}&gt;<br>        Save Changes<br>      &lt;/Button&gt;<br><br>      {/* Case 2: Anchor Link */}<br>      {/* TS automatically allows/requires &#39;href&#39; */}<br>      &lt;Button as=&quot;a&quot; href=&quot;/profile&quot;&gt;<br>        Go to Profile<br>      &lt;/Button&gt;<br>      <br>       {/* Case 3: Impossible State Protection */}<br>       {/* 🚨 Error! Property &#39;href&#39; does not exist on type &#39;button&#39; */}<br>       &lt;Button as=&quot;button&quot; href=&quot;/nowhere&quot;&gt; <br>         Broken<br>       &lt;/Button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>TypeScript protects you from adding an href to a button, or an onClick that doesn&#39;t make sense.</p><h3>7. Closing Thoughts</h3><p>As Frontend Engineers, our goal is to create <strong>Abstractions</strong>, not just screens.</p><p>A Polymorphic component is a tool that respects the HTML standard while providing the Developer Experience (DX) of a modern framework. It separates <em>Logic</em> (what it does) from <em>Visuals</em> (how it looks).</p><p>Next time you find yourself copying styles from a button to a link, stop. Ask yourself: “Is this a new component, or just a new <em>form</em> of the same component?”</p><p>Let’s make our Designs Systems smarter!</p><p>#ReactJS #TypeScript #CleanCode #Frontend #Engineering #WebDev #DesignSystems</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc6da7ec8a4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Using Booleans. Use TypeScript Discriminated Unions]]></title>
            <link>https://medium.com/@pauloeder7/stop-using-booleans-use-typescript-discriminated-unions-a50d6d5548b2?source=rss-f0cbcadb84e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a50d6d5548b2</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Paulo Eder Medeiros Cardoso]]></dc:creator>
            <pubDate>Fri, 23 Jan 2026 18:09:33 GMT</pubDate>
            <atom:updated>2026-01-23T18:09:33.094Z</atom:updated>
            <content:encoded><![CDATA[<p>How to make impossible states impossible. A guide to cleaner React state management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bUEkVGwtm71FX3jL7K9o2Q.png" /></figure><h3>1. The Hook</h3><p>We have all written this component. You need to fetch data, so you add isLoading. Then you need error handling, so you add isError. Then the data itself.</p><p>Suddenly, your state looks like this:</p><pre>// ❌ The Boolean Hell<br>const [isLoading, setIsLoading] = useState(false);<br>const [isError, setIsError] = useState(false);<br>const [data, setData] = useState&lt;User | null&gt;(null);</pre><p>It looks innocent. But let me ask you a question: <strong>What happens if </strong><strong>isLoading is true AND </strong><strong>isError is true?</strong></p><p>The UI tries to show a spinner and an error message at the same time. Or worse, it crashes. This is an <strong>Impossible State</strong>. And yet, your types allow it to exist.</p><h3>2. The Analogy: The Traffic Light</h3><p>Imagine a traffic light controlled by three separate switches:</p><ol><li>🔴 Red Switch</li><li>🟡 Yellow Switch</li><li>🟢 Green Switch</li></ol><p>If you are not careful, you could accidentally flip Red and Green on at the same time. Cars would crash. Chaos.</p><p>A real traffic light doesn’t work like that. It has <strong>one internal state</strong> that can be <em>either</em> Red, <em>or</em> Yellow, <em>or</em> Green. It physically cannot be both.</p><p>In TypeScript, we model this “Traffic Light” safety using <strong>Discriminated Unions</strong>.</p><h3>3. The Problem (The Code)</h3><p>Let’s look at why the Boolean Approach is dangerous in React.</p><pre>interface BadState {<br>  isLoading: boolean;<br>  error: Error | null;<br>  data: User | null;<br>}<br><br>// 🐛 BUG: The &quot;Impossible State&quot;<br>// The compiler thinks this is valid code:<br>const state: BadState = {<br>  isLoading: false, // Not loading...<br>  error: null,      // No error...<br>  data: null        // But no data?<br>};</pre><p>In the example above, the app is doing nothing. It’s a White Screen of Death. The user stares at a blank page because we forgot to handle this specific combination of booleans.</p><h3>4. The Solution: Discriminated Unions</h3><p>Instead of separate booleans, we combine the state into a single type. We use a literal property (usually called status, kind, or type) to &quot;discriminate&quot; between them.</p><pre>// ✅ The &quot;Senior&quot; Way<br>type State =<br>  | { status: &#39;idle&#39; }<br>  | { status: &#39;loading&#39; }<br>  | { status: &#39;error&#39;; error: string }<br>  | { status: &#39;success&#39;; data: User };<br><br>// Now, try to create an invalid state:<br>const state: State = {<br>  status: &#39;loading&#39;,<br>  data: { name: &#39;Paulo&#39; } // 🚨 Error! Property &#39;data&#39; does not exist on type &#39;{ status: &#39;loading&#39; }&#39;<br>};</pre><p>TypeScript now protects you. It knows that if status is &#39;loading&#39;, <strong>there is no data yet</strong>. You physically cannot access it.</p><p>5. Visual Comparison (The Diagram)</p><p><strong>Let’s visualize the architecture gap:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*GCTLneV3VfDn07BbG2pMiw.png" /></figure><ul><li><strong>Top(Boolean Hell):</strong>A chaotic web of conflicting states. The arrows going back and forth represent the confusion: “If it’s loading, can it also have data? If there is an error, is loading still true?” This is where bugs hide.</li><li><strong>Bottom (Discriminated Union):</strong> A clean, linear path. You start at <strong>Idle</strong>, move to <strong>Loading</strong>, and then branch to <strong>Success</strong> or <strong>Error</strong>. It is a one-way street. You can never get lost.</li></ul><h3>6. Why This Matters (The Autocomplete Magic)</h3><p>The best part isn’t just safety, it’s Developer Experience (DX). When you check the status inside your component, TypeScript <strong>narrows</strong> the type automatically.</p><pre>function UserProfile({ state }: { state: State }) {<br>  if (state.status === &#39;loading&#39;) {<br>    return &lt;Spinner /&gt;; // TypeScript knows &#39;data&#39; and &#39;error&#39; don&#39;t exist here.<br>  }<br><br>  if (state.status === &#39;error&#39;) {<br>    return &lt;Alert message={state.error} /&gt;; // TypeScript autocompletes &#39;error&#39;!<br>  }<br><br>  if (state.status === &#39;success&#39;) {<br>    return &lt;h1&gt;Welcome, {state.data.name}&lt;/h1&gt;; // TypeScript autocompletes &#39;data&#39;!<br>  }<br><br>  return null;<br>}</pre><h3>7. Closing Thoughts</h3><p>As Developers, our job isn’t just to write code that works. It’s to write code that cannot break.</p><p>By using Discriminated Unions, you follow the golden rule of architecture: Make impossible states impossible.</p><p>Next time you reach for useState(false), stop. Ask yourself: “Is this a boolean, or is it a state machine?”</p><p>Architecture isn’t just about servers. It’s about how you structure your data.</p><p>Follow for more hands-on TypeScript &amp; React architecture tips. Let’s make bugs impossible 🚀</p><p>#TypeScript #React #CleanCode #SoftwareArchitecture #Frontend #Engineering #DevTips #WebDev</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a50d6d5548b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Alphabet Soup of Web Rendering: CSR, SSR, SSG, and ISR]]></title>
            <link>https://medium.com/@pauloeder7/the-alphabet-soup-of-web-rendering-csr-ssr-ssg-and-isr-522e75fca2c5?source=rss-f0cbcadb84e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/522e75fca2c5</guid>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Paulo Eder Medeiros Cardoso]]></dc:creator>
            <pubDate>Tue, 20 Jan 2026 15:49:51 GMT</pubDate>
            <atom:updated>2026-01-20T15:49:51.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tv6jam74LIx--mTReU0OFg.png" /></figure><h3>Stop guessing how your application renders. A visual guide to modern architecture patterns in Next.js and React.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*VJgAt27O8aqdmgLqrHvXJw.png" /></figure><p>We used to build websites with simple HTML files. It was easy. Today, we have a soup of acronyms: <strong>CSR, SSR, SSG, ISR</strong>. Choosing the wrong one doesn’t just hurt your SEO; it can destroy your user experience and explode your server costs. But what is actually happening under the hood?</p><h3>The Analogy: The Pizza Kitchen</h3><p>To understand rendering, let’s forget code for a second and talk about <strong>Pizza</strong>.</p><ul><li><strong>CSR (Client-Side Rendering) = The Meal Kit.</strong> The restaurant sends you a box of raw ingredients (empty HTML + a heavy JS bundle). You have to go home, chop the vegetables, and cook it yourself (Your browser does the work).</li><li><em>Result:</em> You wait a while before you can eat, but once it’s ready, it’s fresh.</li><li><strong>SSR (Server-Side Rendering) = The Traditional Restaurant.</strong> You order. The chef cooks it from scratch right then and there. The waiter brings a hot, ready-to-eat pizza to your table.</li><li><em>Result:</em> You wait for the chef (Server Latency), but the food arrives ready.</li><li><strong>SSG (Static Site Generation) = The Frozen Store Pizza. </strong>The factory cooked 5,000 pizzas yesterday. When you order, they just hand you one from the freezer.</li><li><em>Result:</em> Instant delivery. But if you want to change an ingredient? Impossible.</li></ul><h3>How it Works (The Technical Flow)</h3><p>Let’s look at the lifecycle of a request in a <strong>Next.js</strong> application.</p><h4>Client-Side Rendering (The Default React Way)</h4><ol><li><strong>Request:</strong> Browser asks for index.html.</li><li><strong>Response:</strong> Server sends an almost empty &lt;div&gt;.</li><li><strong>Loading:</strong> Browser downloads a huge .js bundle.</li><li><strong>Execution:</strong> React runs, fetches data from an API, and finally paints the UI.</li></ol><pre>// ❌ Bad for SEO, ✅ Good for private dashboards<br>import { useState, useEffect } from &#39;react&#39;;<br><br>export default function Dashboard() {<br>  const [data, setData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    // 🐢 Browser fetches data only after downloading JS<br>    fetch(&#39;/api/user-stats&#39;)<br>      .then((res) =&gt; res.json())<br>      .then(setData);<br>  }, []);<br><br>  if (!data) return &lt;Spinner /&gt;;<br>  return &lt;div&gt;Welcome, {data.name}&lt;/div&gt;;<br>}</pre><p><em>The Bottleneck: The user’s device (CPU) and internet speed.</em></p><h4>Server-Side Rendering (The Next.js Power)</h4><ol><li><strong>Request:</strong> Browser asks for index.html.</li><li><strong>Execution:</strong> The Server runs the React logic, fetches data from the DB, and generates the full HTML string.</li><li><strong>Response:</strong> The browser receives a page with content already visible.</li><li><strong>Hydration:</strong> React attaches event listeners to the HTML to make it interactive.</li></ol><pre>// ✅ Great for SEO, ⚠️ Slower TTFB (Time to First Byte)<br>import { GetServerSideProps } from &#39;next&#39;;<br><br>export const getServerSideProps: GetServerSideProps = async (context) =&gt; {<br>  // ⚡ Server fetches data instantly (backend-to-backend)<br>  const res = await fetch(`https://api.example.com/feed`);<br>  const data = await res.json();<br><br>  // Pass data to the page component<br>  return { props: { data } };<br>}<br><br>export default function Feed({ data }: { data: FeedData }) {<br>  return &lt;div&gt;Latest News: {data.title}&lt;/div&gt;; // Rendered on Server!<br>}</pre><ul><li><em>The Bottleneck:</em> Your database query speed.</li></ul><blockquote><strong><em>Key Concept: Hydration</em></strong><em> Think of Hydration as waking up the static HTML. The page looks ready, but buttons won’t work until React hydrates the DOM with JavaScript listeners.</em></blockquote><h3>Real-World Comparison</h3><p>When should you use each strategy?</p><p><strong>🔵 SSG (Static Site Generation)</strong></p><ul><li><strong>Best for:</strong> Marketing pages, Blogs, Documentation.</li><li><strong>Why:</strong> The content doesn’t change per user. It’s HTML sitting on a CDN.</li><li><strong>Pros:</strong> Fastest possible TTFB (Time to First Byte).</li><li><strong>Cons:</strong> Can’t show real-time data.</li></ul><p><strong>🟢 SSR (Server-Side Rendering)</strong></p><ul><li><strong>Best for:</strong> Social Media Feeds, Personalized Dashboards.</li><li><strong>Why:</strong> Every user sees different data. You need to check the database <em>every single request</em>.</li><li><strong>Pros:</strong> Great SEO, fresh data.</li><li><strong>Cons:</strong> Higher server costs, slower initial response if DB is slow.</li></ul><p><strong>🟡 ISR (Incremental Static Regeneration)</strong></p><ul><li><strong>The “Hybrid”:</strong> Imagine SSG, but the server rebuilds the page in the background every x minutes.</li><li><strong>Best for:</strong> E-commerce Product Pages. You get the speed of Static, but prices update every 10 minutes.</li></ul><h3>5. Closing Thoughts</h3><p>In modern Full-Stack development, you aren’t stuck with just one. The power of frameworks like <strong>Next.js</strong> is that they allow you to mix these patterns. You can have a <strong>Static</strong> Landing Page (SSG), a <strong>Dynamic</strong> Dashboard (SSR), and a <strong>Client-Side</strong> settings panel (CSR) all in the same app.</p><p>Architecture isn’t about memorizing acronyms. It’s about knowing <strong>where</strong> to put the load: on the User (Client) or on the Infrastructure (Server).</p><p>Follow for more hands-on Full-Stack architecture tips. Let’s make the web instant 🚀</p><p>#NextJS #React #WebPerformance #SoftwareArchitecture #Frontend #Engineering #DevTips #FullStack</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=522e75fca2c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>