<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wallace Leonardo</title>
    <description>The latest articles on DEV Community by Wallace Leonardo (@wallace-leo).</description>
    <link>https://dev.to/wallace-leo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1338693%2F5b947704-8a2e-42a4-ae72-a7de27abc960.jpg</url>
      <title>DEV Community: Wallace Leonardo</title>
      <link>https://dev.to/wallace-leo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wallace-leo"/>
    <language>en</language>
    <item>
      <title>🚀 Using enum with key-value objects in the Front-end: a more scalable approach</title>
      <dc:creator>Wallace Leonardo</dc:creator>
      <pubDate>Fri, 26 Sep 2025 19:09:23 +0000</pubDate>
      <link>https://dev.to/wallace-leo/using-enum-with-key-value-objects-in-the-front-end-a-more-scalable-approach-3ij2</link>
      <guid>https://dev.to/wallace-leo/using-enum-with-key-value-objects-in-the-front-end-a-more-scalable-approach-3ij2</guid>
      <description>&lt;p&gt;When we need to render components based on different parameters, the most common solution is to use conditionals such as if or switch. However, these approaches can become less scalable as the codebase grows.&lt;/p&gt;

&lt;p&gt;Let’s compare three approaches:&lt;/p&gt;

&lt;p&gt;🔹 Switch approach&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3v1xz80rbpirzk75o03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3v1xz80rbpirzk75o03.png" alt=" " width="753" height="290"&gt;&lt;/a&gt;&lt;br&gt;
✅ Simple to implement&lt;br&gt;
❌ Becomes repetitive and harder to scale&lt;/p&gt;

&lt;p&gt;🔹 Conditional (if/else) approach&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hgh7zfy9rckuoqpphtv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hgh7zfy9rckuoqpphtv.png" alt=" " width="716" height="282"&gt;&lt;/a&gt;&lt;br&gt;
✅ Easy to read in simple cases&lt;br&gt;
❌ Gets messy when multiple variations are needed&lt;/p&gt;

&lt;p&gt;🔹 enum + key-value object approach&lt;/p&gt;

&lt;p&gt;Using enums with key-value objects in the front-end allows you to organize data in a clean and reusable way. Instead of repetitive conditionals, you centralize related values (such as classes and labels) into easy-to-maintain structures.&lt;/p&gt;

&lt;p&gt;This makes the code more readable, scalable, and type-safe when combined with TypeScript.&lt;/p&gt;

&lt;p&gt;Why use it?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoids code duplication&lt;/li&gt;
&lt;li&gt;Centralizes values in one place&lt;/li&gt;
&lt;li&gt;Leverages TypeScript’s type safety&lt;/li&gt;
&lt;li&gt;Scales much better when adding new cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fid8rkwb3wgx6kwi423sv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fid8rkwb3wgx6kwi423sv.png" alt=" " width="577" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ih76mwqzl1b6s8m0bhp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ih76mwqzl1b6s8m0bhp.png" alt=" " width="707" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✅ Cleaner code&lt;br&gt;
✅ Easier to maintain&lt;br&gt;
✅ Strong typing prevents mistakes&lt;br&gt;
✅ Highly scalable when adding new variations&lt;/p&gt;

&lt;p&gt;🔹 Why does this matter in the front-end?&lt;/p&gt;

&lt;p&gt;Using enum with key-value objects provides:&lt;/p&gt;

&lt;p&gt;Scalability: new variations can be added easily without editing multiple places.&lt;/p&gt;

&lt;p&gt;Organization: styles and labels are centralized.&lt;/p&gt;

&lt;p&gt;Reusability: the same objects can be reused across multiple components.&lt;/p&gt;

&lt;p&gt;Type safety: ensures that only valid values are passed.&lt;/p&gt;

&lt;p&gt;In larger projects, this approach aligns with how design systems are built — separating style tokens (colors, sizes, variants) from component logic.&lt;/p&gt;

&lt;p&gt;🔹 Conclusion&lt;/p&gt;

&lt;p&gt;While if and switch work fine for simple cases, using enum + key-value objects is a practice that brings clarity, consistency, and scalability to front-end development — especially when working with TypeScript.&lt;/p&gt;

&lt;p&gt;If you deal with multiple UI variations, this approach can significantly improve code maintainability and evolution.&lt;/p&gt;

&lt;p&gt;What’s your go-to approach for rendering different component states? I’d love to hear other strategies from the community.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
