<?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>Forem: Wild Boar Dev</title>
    <description>The latest articles on Forem by Wild Boar Dev (@wildboar_developer).</description>
    <link>https://forem.com/wildboar_developer</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%2F3189290%2Ff9dddac4-90bc-41f5-b814-dff7b57d9a10.png</url>
      <title>Forem: Wild Boar Dev</title>
      <link>https://forem.com/wildboar_developer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wildboar_developer"/>
    <language>en</language>
    <item>
      <title>Static Single Assignment (SSA)</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Wed, 17 Sep 2025 04:54:29 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/static-single-assignment-ssa-51m3</link>
      <guid>https://forem.com/wildboar_developer/static-single-assignment-ssa-51m3</guid>
      <description>&lt;h2&gt;
  
  
  1️⃣ What is SSA?
&lt;/h2&gt;

&lt;p&gt;SSA is a way of representing code where:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each &lt;strong&gt;variable&lt;/strong&gt; is assigned &lt;strong&gt;exactly once&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;If a variable is reassigned → the compiler creates a new “version” of that variable (&lt;code&gt;x1&lt;/code&gt;, &lt;code&gt;x2&lt;/code&gt;, &lt;code&gt;x3&lt;/code&gt; …).
&lt;/li&gt;
&lt;li&gt;When there are multiple control-flow branches (&lt;code&gt;if/else&lt;/code&gt;), the compiler uses a &lt;strong&gt;φ-function&lt;/strong&gt; to “merge” values back together.
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;🔎 &lt;strong&gt;Note:&lt;/strong&gt; SSA is not a new kind of IR on its own, but rather a &lt;strong&gt;specialized form of IR&lt;/strong&gt;. Compilers convert their &lt;a href=""&gt;Intermediate Representation (IR)&lt;/a&gt; into SSA form to make analysis and optimization easier.  &lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  2️⃣ Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Normal
&lt;/h3&gt;

&lt;p&gt;Original code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After converting to SSA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;y1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Branching (if/else)
&lt;/h3&gt;

&lt;p&gt;Original code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cond&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After converting to SSA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cond&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;x1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;x2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;x3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;φ&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;y1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x3&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Loop (while)
&lt;/h3&gt;

&lt;p&gt;Original code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After converting to SSA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;i0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// φ-functions to bring values back into the loop&lt;/span&gt;
  &lt;span class="nx"&gt;sum0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;φ&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;i0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;φ&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3️⃣ What is the φ-function?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;φ (phi-function)&lt;/strong&gt; is a special notation in SSA, &lt;strong&gt;not an actual runtime function&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It only exists during &lt;strong&gt;compiler analysis of control flow&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Its role is to &lt;strong&gt;select the correct value depending on which branch was executed&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;cond&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt; → &lt;code&gt;x3 = x1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If &lt;code&gt;cond&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt; → &lt;code&gt;x3 = x2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In other words: φ acts as a “bridge” that unifies variables from different branches into a single one in SSA.&lt;/p&gt;




&lt;h2&gt;
  
  
  4️⃣ Why is SSA important?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Simplifies analysis: every variable has exactly one definition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enables stronger optimizations: such as constant propagation, dead code elimination, and register allocation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5️⃣ Extensions and Variations of SSA
&lt;/h2&gt;

&lt;p&gt;SSA is a flexible and extensible representation, and several variations have been developed to improve its performance and adaptability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimal SSA&lt;/strong&gt;: This extension seeks to insert the minimal number of &lt;strong&gt;Φ-functions&lt;/strong&gt; while ensuring that each variable is assigned exactly once.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pruned SSA&lt;/strong&gt;: This variant avoids inserting unnecessary &lt;strong&gt;Φ-functions&lt;/strong&gt; by considering live-variable information during the SSA construction process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Semi-pruned SSA&lt;/strong&gt;: A more efficient variation that omits &lt;strong&gt;Φ-functions&lt;/strong&gt; for variables that are not live when they enter a basic block.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Block arguments&lt;/strong&gt;: An alternative to &lt;strong&gt;Φ-functions&lt;/strong&gt;, where block arguments are used to represent control-flow merges in a way that is more convenient for optimization. Some compilers like &lt;strong&gt;LLVM MLIR&lt;/strong&gt; and &lt;strong&gt;Swift SIL&lt;/strong&gt; use block arguments.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 Conclusion
&lt;/h2&gt;

&lt;p&gt;SSA isn’t just a theoretical concept - it’s the foundation of most modern compilers. It simplifies dataflow analysis and optimization, making compilers more efficient. In short, SSA is the secret sauce that enables compilers to be both smart in analyzing code and powerful in optimizing it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Static_single-assignment_form" rel="noopener noreferrer"&gt;Static single-assignment form - wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cs.cornell.edu/courses/cs6120/2022sp/lesson/6/" rel="noopener noreferrer"&gt;Static Single Assignment - Cornell University&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/compiler-design/static-single-assignment-with-relevant-examples/" rel="noopener noreferrer"&gt;Static Single Assignment (with relevant examples) - Geeks for Greeks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>learning</category>
      <category>performance</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Intermediate Representation (IR): An Easy Overview</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Mon, 09 Jun 2025 15:28:25 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/intermediate-representation-ir-an-easy-overview-383c</link>
      <guid>https://forem.com/wildboar_developer/intermediate-representation-ir-an-easy-overview-383c</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intermediate Representation (IR)&lt;/strong&gt; is like a translation of your code into a simpler, more structured version — just for the computer.&lt;/p&gt;

&lt;p&gt;It’s not exactly the code you wrote, and it’s not machine code either. It’s in the middle, and it helps the compiler do its job: check, analyze, and make the code faster before it runs.&lt;/p&gt;

&lt;p&gt;In short, It is the middle layer that helps compilers understand and improve your code.&lt;/p&gt;




&lt;h2&gt;
  
  
  🗂️ Are there different types of IR?
&lt;/h2&gt;

&lt;p&gt;Yes! Most modern compilers break IR into multiple layers, going from high-level (close to your original code) down to low-level (closer to machine code):&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%2Fbngaegn2dmw1g6ecwfce.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%2Fbngaegn2dmw1g6ecwfce.png" alt="The IR flow" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  1️⃣ HIR – High-level IR
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Still looks a lot like your original code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keeps &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, and other logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy for the compiler to analyze what the code means, but not ready for optimization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2️⃣ MIR – Mid-level IR
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Splits big expressions into simple steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Much easier for the compiler to optimize or rearrange.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t1 = user.isLoggedIn  
t2 = user.hasRole("admin")  
t3 = t1 &amp;amp;&amp;amp; t2  
if (t3) goto BLOCK_ADMIN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3️⃣ LIR – Low-level IR
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now the code looks like instructions for the machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You’ll see low-level operations like &lt;code&gt;LOAD&lt;/code&gt;, &lt;code&gt;CMP&lt;/code&gt;, &lt;code&gt;JUMP&lt;/code&gt;,...&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOAD R1, user.isLoggedIn  
LOAD R2, user.hasRole  
CALL R2, "admin"  
AND R3, R1, R2  
CMP R3, 0  
JZ END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⁉️ How Compilers Understand IR?
&lt;/h2&gt;

&lt;p&gt;To make sense of your program, compilers don’t just read code line by line — they look at how the logic flows. That’s where Control-Flow Graphs (CFGs) come in.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;CFG&lt;/strong&gt; is like a roadmap that shows all the different routes your program might follow as it runs.&lt;/li&gt;
&lt;li&gt;It breaks your code into &lt;strong&gt;basic blocks&lt;/strong&gt; — small, straight pieces of code with no jumps — and connects them based on decisions like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, or &lt;code&gt;loops&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;This helps the compiler understand your program's logic clearly, clean up unused code, and make everything run faster.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&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%2F2dedgpivn6kk6rqobzdp.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%2F2dedgpivn6kk6rqobzdp.png" alt="CFG of HIR" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚒️ Tools that use IR
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Tool / Compiler&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;LLVM (Clang, Swift)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses powerful LLVM IR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Rust&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses HIR → MIR → LLVM IR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;React Compiler&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses HIR and reactive scopes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;V8 (Chrome JS engine)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses internal IR for JIT compilation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🎯 Conclusion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;IR is how your code becomes smarter before it runs.&lt;/strong&gt;&lt;br&gt;
It helps compilers understand, improve, and prepare your program step by step.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build developer tools.&lt;/li&gt;
&lt;li&gt;Work with performance-critical code.&lt;/li&gt;
&lt;li&gt;Want to dive deeper into how compilers think.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔗 References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Intermediate_representation" rel="noopener noreferrer"&gt;Intermediate representation - wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/introduction-to-intermediate-representationir/" rel="noopener noreferrer"&gt;Introduction to Intermediate Representation(IR) - geeksforgeeks.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.piovezan.ca/compilers/llvm_ir_p1/" rel="noopener noreferrer"&gt;What is an Intermediate Representation? - piovezan blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.washi.dev/echo/guides/core/cfg-basics.html" rel="noopener noreferrer"&gt;CFG Basic - docs.washi.dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Control-flow_graph" rel="noopener noreferrer"&gt;CFG - wiki&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  😊 Thanks for reading!
&lt;/h3&gt;

</description>
      <category>programming</category>
      <category>performance</category>
      <category>computerscience</category>
      <category>coding</category>
    </item>
    <item>
      <title>What Is an Abstract Syntax Tree (AST)? Explained Simply</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Sun, 08 Jun 2025 10:23:16 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/what-is-an-abstract-syntax-tree-ast-explained-simply-114h</link>
      <guid>https://forem.com/wildboar_developer/what-is-an-abstract-syntax-tree-ast-explained-simply-114h</guid>
      <description>&lt;p&gt;When you write code, the computer doesn’t understand it the same way humans do. Instead, compilers or code analysis tools convert the source code into a tree-like data structure called an AST – Abstract Syntax Tree, which is then used for tasks like error checking, optimization, or compilation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note:&lt;/strong&gt; AST exists in many programming languages, but I’ll use JavaScript as a specific example.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🌳 What is an Abstract Syntax Tree?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;An AST (Abstract Syntax Tree) is an abstract representation of source code in the form of a hierarchical tree structure. Each node in the tree represents a syntactic element of the program, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables – Representing values or references.&lt;/li&gt;
&lt;li&gt;Operators – Like &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Functions – Logical units of computation.&lt;/li&gt;
&lt;li&gt;Conditional statements – Like if.&lt;/li&gt;
&lt;li&gt;Loops – Such as for, while.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;An AST omits syntactic details that are not logically important, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Semicolons (&lt;code&gt;;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Parentheses or braces (&lt;code&gt;()&lt;/code&gt;, &lt;code&gt;{}&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Line breaks, indentation, formatting.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;The goal is to focus solely on the actual logic and structure of the code.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;




&lt;p&gt;This is how a compiler &lt;em&gt;“understands”&lt;/em&gt; your code.&lt;/p&gt;

&lt;p&gt;Original source code (JavaScript):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Corresponding AST:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VariableDeclaration"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"const"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"declarations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VariableDeclarator"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Identifier"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sum"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"init"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"BinaryExpression"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"operator"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"+"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"left"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Identifier"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"right"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Identifier"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"b"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;VariableDeclaration: Declares a variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BinaryExpression: A mathematical expression (&lt;code&gt;a + b&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identifier: The variables &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, and &lt;code&gt;sum&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔧 What is AST used for?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Syntax Parsing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checks whether the code is syntactically correct.&lt;/li&gt;
&lt;li&gt;Detects issues like missing parentheses, improperly nested functions, or invalid structures.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Code Optimization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Removes unused variables (dead code).&lt;/li&gt;
&lt;li&gt;Simplifies mathematical or logical expressions (e.g., &lt;code&gt;a * 1 → a&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Transpilation (Syntax Transformation)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converts newer syntax into older syntax.&lt;/li&gt;
&lt;li&gt;Example: Babel transforms ES6 into ES5 to support older browsers.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Linting and Auto-fixing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tools like ESLint and TSLint use AST to detect code style or logic violations.&lt;/li&gt;
&lt;li&gt;Can automatically fix issues like converting &lt;code&gt;var&lt;/code&gt; to &lt;code&gt;let&lt;/code&gt; or removing unnecessary parentheses.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Code Formatting&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tools like Prettier use AST to restructure code for consistent and readable formatting — without changing logic.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Refactoring (Automated Code Restructuring)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rename variables or functions without breaking references.&lt;/li&gt;
&lt;li&gt;Add function parameters, move code across modules safely and correctly.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 Real-world Tools That Use AST
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Tool&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Babel&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Transforms modern JavaScript syntax into older versions (e.g., ES6 → ES5)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;ESLint&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Analyzes code to detect and warn about potential errors and style violations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Prettier&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Automatically formats code for consistent style without changing behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;AST Explorer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Web-based interface to view and explore the AST of your code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TypeScript&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses its own AST to support static type checking and code transformation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;React Compiler&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses AST to analyze and optimize React hooks and component logic&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🎯 Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Understanding AST is simply about knowing how a computer &lt;em&gt;"reads"&lt;/em&gt; and interprets your code.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once you grasp how AST works, it becomes much easier to visualize how compilers or linters process each line of code. From there, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build custom tools tailored to your project&lt;/li&gt;
&lt;li&gt;Refactor code with confidence, without breaking logic&lt;/li&gt;
&lt;li&gt;Optimize performance for large applications in a clear and controlled way&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Whether you're working on frontend, backend, or developer tooling, understanding how AST works will broaden your perspective and strengthen your foundational knowledge of how code is processed behind the scenes.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔗 References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree" rel="noopener noreferrer"&gt;Abstract syntax tree - wiki&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://jotadeveloper.medium.com/abstract-syntax-trees-on-javascript-534e33361fc7" rel="noopener noreferrer"&gt;Abstract syntax tree - medium&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nearform.com/insights/what-is-an-abstract-syntax-tree/" rel="noopener noreferrer"&gt;What is an Abstract Syntax Tree? - nearform.com&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  😘 Thanks for reading!
&lt;/h3&gt;

</description>
      <category>babel</category>
      <category>learning</category>
      <category>abstract</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Concept, Pattern, Structure and Architecture – What’s the Difference?</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Wed, 28 May 2025 06:54:26 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/concept-vs-pattern-vs-structure-vs-architecture-whats-the-difference-3h6j</link>
      <guid>https://forem.com/wildboar_developer/concept-vs-pattern-vs-structure-vs-architecture-whats-the-difference-3h6j</guid>
      <description>&lt;h2&gt;
  
  
  Quick Comparison:
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Aspect&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Concept 💡&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Design Pattern 🛠️&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Structure 🏗️&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Architecture 🏛️&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A basic idea or way of thinking about how code works.&lt;/td&gt;
&lt;td&gt;Reusable solution to a problem&lt;/td&gt;
&lt;td&gt;How project files and parts are set&lt;/td&gt;
&lt;td&gt;Big system design and interaction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;To help write clear and simple code.&lt;/td&gt;
&lt;td&gt;Solve design problems clearly&lt;/td&gt;
&lt;td&gt;Keep project organized&lt;/td&gt;
&lt;td&gt;Make system scalable and maintainable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Used when planning and thinking about problems.&lt;/td&gt;
&lt;td&gt;Used directly in code&lt;/td&gt;
&lt;td&gt;Organize folders and files&lt;/td&gt;
&lt;td&gt;Design whole system structure, flow,...&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scope&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mindset for individuals or teams&lt;/td&gt;
&lt;td&gt;Code-level technique&lt;/td&gt;
&lt;td&gt;Project-level layout&lt;/td&gt;
&lt;td&gt;System-wide design&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Impact&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Influences how you write and organize your code.&lt;/td&gt;
&lt;td&gt;Affects solving coding issues&lt;/td&gt;
&lt;td&gt;Affects code clarity and teamwork&lt;/td&gt;
&lt;td&gt;Affects system performance &amp;amp; maintenance&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  In short:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;💡 Concept&lt;/strong&gt; → A basic idea or way of thinking that helps us understand or write code.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🛠️ Design Pattern&lt;/strong&gt; → A solution to a specific coding/design problem
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🏗️ Structure&lt;/strong&gt; → How code and folders are physically organized.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🏛️ Architecture&lt;/strong&gt; → The system detail, interactions, and flow.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;Below, I will use React as an example.&lt;/p&gt;

&lt;h3&gt;
  
  
  💡 Concept
&lt;/h3&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%2Fifsu65zo2s1zwjvo5s98.jpg" 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%2Fifsu65zo2s1zwjvo5s98.jpg" alt="The concepts of react" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The key concept in React is building user interfaces with small, reusable pieces called components. React’s concept is to describe what the UI should look like based on data, not how to change it. When data changes, React updates the screen automatically. Other important concepts like props, state, and hooks help you manage data and behavior, keeping your app organized and fast.&lt;/p&gt;

&lt;h3&gt;
  
  
  🛠️ Design Pattern
&lt;/h3&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%2F9zpplkfct0hzkjp79o6l.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%2F9zpplkfct0hzkjp79o6l.png" alt="Context pattern in react" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Context Pattern in React is a design pattern that allows you to pass data to deep child components without going through every intermediate level (avoiding prop drilling). It uses the Context API as a shared data channel between components. This pattern is efficient, reusable, and helps keep your code clean in large applications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Here, “context” is both a concept and a design pattern, so I’ll keep the explanation simple.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Context (Concept):&lt;/strong&gt;&lt;/em&gt;
&lt;em&gt;Using information from nearby parts of the program to help a component know what to do or how to behave.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Context (Design Pattern):&lt;/strong&gt;&lt;/em&gt;
&lt;em&gt;A way to store and share useful data in one place (a "context object") so that other parts of the system can access it easily.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  🏗️ Structure
&lt;/h3&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%2Fvfcjjz5somnj3stx3s6d.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%2Fvfcjjz5somnj3stx3s6d.png" alt="A basic structure" width="491" height="784"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A basic structure for a React project that splits components, pages, and utils for easier management.&lt;/p&gt;

&lt;h3&gt;
  
  
  🏛️ Architecture
&lt;/h3&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%2Faqiv62tlv5viemxyqu1g.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%2Faqiv62tlv5viemxyqu1g.png" alt="A basic architecture for a web app" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This picture shows an architecture where a React app uses Redux to manage its data. When something happens in the app, it can send or receive data through a server. The server communicates with a database to save or load information.&lt;/p&gt;




&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Concept_(generic_programming)" rel="noopener noreferrer"&gt;Wiki - concept&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.alooba.com/skills/concepts/programming/programming-concepts/" rel="noopener noreferrer"&gt;Programming Concepts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.educative.io/answers/what-are-the-basic-fundamental-concepts-of-programming" rel="noopener noreferrer"&gt;What are the basic fundamental concepts of programming?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/pulse/programming-concept-you-need-know-beginner-rexford-koomson" rel="noopener noreferrer"&gt;Programming Concept you need to know as a beginner&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sourcemaking.com/design_patterns" rel="noopener noreferrer"&gt;Design Pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Software_design_pattern" rel="noopener noreferrer"&gt;Wiki - Design Pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://refactoring.guru/design-patterns/what-is-pattern" rel="noopener noreferrer"&gt;What's a design pattern?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Structured_programming" rel="noopener noreferrer"&gt;Wiki - Structure Programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/what-is-the-basic-structure-of-a-programming-language" rel="noopener noreferrer"&gt;What is the Basic Structure of a Programming Language?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Software_architecture" rel="noopener noreferrer"&gt;Wiki - Software Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://insights.sei.cmu.edu/software-architecture/" rel="noopener noreferrer"&gt;Software Architecture - CMU&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  😊 Thanks for reading! Happy coding!
&lt;/h3&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>react</category>
    </item>
    <item>
      <title>Install Fewer Libraries – Not to Be “Pure”, But to Be Smarter 🔻📦 👉 🎉</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Mon, 26 May 2025 02:07:53 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/install-fewer-libraries-not-to-be-pure-but-to-be-smarter-3fnf</link>
      <guid>https://forem.com/wildboar_developer/install-fewer-libraries-not-to-be-pure-but-to-be-smarter-3fnf</guid>
      <description>&lt;h3&gt;
  
  
  📌 Note before we begin:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;You might already know (or do) most of what’s in this post — and that’s great.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Think of this as a quick reference, not a rulebook. Use it to reflect, refine, or share with your team.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🔰 Introduction
&lt;/h3&gt;

&lt;p&gt;In modern software development, there's a library for almost everything:&lt;/p&gt;

&lt;p&gt;Debouncing, date formatting, data validation, API calls, routing, state management, database queries, caching, logging...&lt;/p&gt;

&lt;p&gt;And that abundance creates a common habit:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Found a library? Just install it.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But every &lt;code&gt;npm install&lt;/code&gt; does more than just add functionality.&lt;br&gt;&lt;br&gt;
It introduces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More bundle size
&lt;/li&gt;
&lt;li&gt;More maintenance overhead
&lt;/li&gt;
&lt;li&gt;More potential security risks
&lt;/li&gt;
&lt;li&gt;And less control over your system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let’s break down the &lt;strong&gt;benefits of using fewer libraries&lt;/strong&gt; — and more importantly, &lt;strong&gt;when it actually makes sense to avoid or include them&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎯 Benefits of Using Fewer Libraries
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1️⃣ Smaller Bundles = Better Performance
&lt;/h4&gt;

&lt;p&gt;Every library adds weight:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the frontend: increased bundle size → slower load time&lt;/li&gt;
&lt;li&gt;On the backend: longer startup time, more memory usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 &lt;em&gt;Example: Instead of importing all of &lt;code&gt;lodash&lt;/code&gt;, just use &lt;code&gt;lodash/debounce&lt;/code&gt; — or better yet, write your own &lt;code&gt;debounce()&lt;/code&gt; in ~10 lines.&lt;/em&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  2️⃣ Greater Control Over Your Codebase
&lt;/h4&gt;

&lt;p&gt;Less third-party code = fewer black boxes.&lt;br&gt;&lt;br&gt;
You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand what your code is doing&lt;/li&gt;
&lt;li&gt;Debug faster&lt;/li&gt;
&lt;li&gt;Refactor with confidence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You're not stuck waiting for a library to fix a bug you can't see.&lt;/p&gt;




&lt;h4&gt;
  
  
  3️⃣ Reduced Dependency Risk
&lt;/h4&gt;

&lt;p&gt;Every dependency is a risk:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❗ Could contain security vulnerabilities
&lt;/li&gt;
&lt;li&gt;⚠️ Could introduce breaking changes in future updates
&lt;/li&gt;
&lt;li&gt;⛔ Could be deprecated or unmaintained at any time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fewer dependencies you have, the lower the blast radius.&lt;/p&gt;




&lt;h4&gt;
  
  
  4️⃣ Lower Technical Debt
&lt;/h4&gt;

&lt;p&gt;Some libraries solve problems &lt;em&gt;now&lt;/em&gt;, but create long-term pain.&lt;/p&gt;

&lt;p&gt;📌 &lt;em&gt;Example: Using a rigid UI kit or ORM might seem fast at first — but if you want to switch frameworks or change structure later, it can be a nightmare to decouple.&lt;/em&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  5️⃣ Easier Maintenance &amp;amp; Upgrade Path
&lt;/h4&gt;

&lt;p&gt;Less to track. Less to break.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fewer version mismatches
&lt;/li&gt;
&lt;li&gt;Fewer conflicts in package trees
&lt;/li&gt;
&lt;li&gt;Faster CI/CD pipelines
&lt;/li&gt;
&lt;li&gt;Simpler testing&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  6️⃣ Deepen Your Understanding
&lt;/h4&gt;

&lt;p&gt;Writing small utility code yourself helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn native Web APIs or Node.js internals
&lt;/li&gt;
&lt;li&gt;Understand how libraries/frameworks work under the hood
&lt;/li&gt;
&lt;li&gt;Develop better architectural thinking and engineering discipline&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal isn’t to &lt;em&gt;avoid&lt;/em&gt; libraries — but to not use them as a crutch.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚖️ When Should You Use a Library?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Should Use?&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Simple data validation&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;A few lines of logic is enough&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex schema validation&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;zod&lt;/code&gt;, &lt;code&gt;yup&lt;/code&gt;, etc. for clarity and scalability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Basic state or cache management&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useContext&lt;/code&gt; or in-memory store is sufficient&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex state logic, persistence needed&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;Zustand&lt;/code&gt;, &lt;code&gt;Redux&lt;/code&gt;, or modular state services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Basic date formatting&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; covers most needs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Handling timezones or calendars&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;dayjs&lt;/code&gt;, &lt;code&gt;date-fns&lt;/code&gt;, &lt;code&gt;luxon&lt;/code&gt;…&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  🧪 Case Study: Context vs State Manager
&lt;/h3&gt;

&lt;h4&gt;
  
  
  ❌ When You DON’T Need a Library:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Your app is small
&lt;/li&gt;
&lt;li&gt;You only pass props down a few levels
&lt;/li&gt;
&lt;li&gt;Your CRUD logic is straightforward&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  ✅ When You DO:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You manage different types of state (UI, data, server)
&lt;/li&gt;
&lt;li&gt;You want to optimize rendering or cache data
&lt;/li&gt;
&lt;li&gt;You need persistence or modularization
&lt;/li&gt;
&lt;li&gt;You require shared logic across multiple parts of the app&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In those cases, libraries like &lt;code&gt;Zustand&lt;/code&gt;, &lt;code&gt;React Query&lt;/code&gt;, &lt;code&gt;Prisma&lt;/code&gt;, or &lt;code&gt;Sequelize&lt;/code&gt; provide real value — they solve complex problems in a clean, scalable way.&lt;/p&gt;




&lt;h3&gt;
  
  
  🚫 Don’t Be Extreme: Know When to Use a Library
&lt;/h3&gt;

&lt;p&gt;This isn’t about being a “pure coder”. It’s about &lt;strong&gt;being intentional&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Use a library &lt;strong&gt;when&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;✅ The problem is complex and error-prone (e.g. timezone handling, debounce, API caching).&lt;br&gt;
✅ You need reliability and coverage (e.g. encryption, auth, validation).&lt;br&gt;
✅ The library adds productivity with &lt;strong&gt;minimal downside&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  📌 A Pre-Install Checklist
&lt;/h3&gt;

&lt;p&gt;Before typing &lt;code&gt;npm install&lt;/code&gt;, ask yourself:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do I &lt;strong&gt;really understand&lt;/strong&gt; the problem I'm trying to solve?
&lt;/li&gt;
&lt;li&gt;Can I write this in &lt;strong&gt;under 20 lines&lt;/strong&gt; myself?
&lt;/li&gt;
&lt;li&gt;What are the &lt;strong&gt;performance, maintenance, or security&lt;/strong&gt; trade-offs of this library?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 If it's simple → &lt;strong&gt;Write it yourself.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 If it's complex → &lt;strong&gt;Install it — but do it intentionally.&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🎯 Conclusion
&lt;/h3&gt;

&lt;p&gt;Using libraries isn't wrong.&lt;br&gt;
&lt;strong&gt;Using them blindly is.&lt;/strong&gt;&lt;br&gt;
You don’t have to code everything from scratch.&lt;br&gt;&lt;br&gt;
You don’t have to “purify” your project of all external tools.&lt;br&gt;
But you should stay &lt;strong&gt;deliberate&lt;/strong&gt; about what you bring in — because it directly impacts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance
&lt;/li&gt;
&lt;li&gt;Maintainability
&lt;/li&gt;
&lt;li&gt;Long-term flexibility
&lt;/li&gt;
&lt;li&gt;And your own growth as a developer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use fewer libraries not to prove a point — but to build smarter.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>performance</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Why Type Is the Better Choice in React + TypeScript</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Sun, 25 May 2025 02:55:40 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/why-type-is-the-better-choice-in-react-typescript-1njm</link>
      <guid>https://forem.com/wildboar_developer/why-type-is-the-better-choice-in-react-typescript-1njm</guid>
      <description>&lt;p&gt;&lt;em&gt;📝 Important note: Whether to use &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;interface&lt;/code&gt; depends on your team’s or company’s conventions. If there is an established rule, please follow it. This article is for reference, for those who are unsure or want to find the best approach when using React + TypeScript.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;React is now one of the most widely used UI libraries in modern web development. When combined with TypeScript, it provides a powerful, safe, and scalable development environment.&lt;/p&gt;

&lt;p&gt;However, one common question is: &lt;strong&gt;should you use &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;interface&lt;/code&gt; to define data types in React projects?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Although both can describe data structures, they have &lt;strong&gt;different characteristics&lt;/strong&gt; and &lt;strong&gt;use cases&lt;/strong&gt; — especially important when writing React code in a &lt;strong&gt;functional programming&lt;/strong&gt; style.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Comparing &lt;code&gt;interface&lt;/code&gt; vs &lt;code&gt;type&lt;/code&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Criteria&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;&lt;code&gt;interface&lt;/code&gt;&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;&lt;code&gt;type&lt;/code&gt;&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mainly for objects and class structures&lt;/td&gt;
&lt;td&gt;More flexible: object, union, intersection, tuple, primitive types&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Inheritance / Extension&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Use &lt;code&gt;extends&lt;/code&gt; to inherit&lt;/td&gt;
&lt;td&gt;✅ Use &lt;code&gt;&amp;amp;&lt;/code&gt; to combine multiple types&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Merge (declaration merging)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Can be declared multiple times (auto-merged)&lt;/td&gt;
&lt;td&gt;❌ Cannot merge; duplicate names cause an error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Suitable for classes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Ideal for &lt;code&gt;class&lt;/code&gt; with &lt;code&gt;implements&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;❌ Not valid for &lt;code&gt;implements&lt;/code&gt; in classes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Suitable for function components&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Usable&lt;/td&gt;
&lt;td&gt;✅ Preferred: cleaner &amp;amp; more concise for props&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Union / Intersection / Tuple&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Not directly supported&lt;/td&gt;
&lt;td&gt;✅ Fully supported&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Extensibility in libraries&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Can extend external types (e.g., &lt;code&gt;Express.Request&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;❌ Cannot extend external types (no declaration merging)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Compatibility with utility types&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Works well&lt;/td&gt;
&lt;td&gt;✅ Works slightly better (&lt;code&gt;Partial&lt;/code&gt;, &lt;code&gt;Omit&lt;/code&gt;, &lt;code&gt;ReturnType&lt;/code&gt;, etc.)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mapped types / &lt;code&gt;keyof&lt;/code&gt; / &lt;code&gt;infer&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;⚠️ Limited&lt;/td&gt;
&lt;td&gt;✅ Fully supported with generics, mapped types, and inference&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  3. Which one fits better when coding React?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ &lt;code&gt;type&lt;/code&gt; is more suitable in modern React
&lt;/h3&gt;

&lt;p&gt;In the context where &lt;strong&gt;React Functional Components are the standard&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You &lt;strong&gt;don’t use classes&lt;/strong&gt;, removing the advantage of &lt;code&gt;interface&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You often need to combine types (&lt;code&gt;&amp;amp;&lt;/code&gt;), create unions (&lt;code&gt;|&lt;/code&gt;), or use utility types → &lt;code&gt;type&lt;/code&gt; handles these better.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;type&lt;/code&gt; supports aliases for primitive types&lt;/strong&gt; like &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt; — something &lt;code&gt;interface&lt;/code&gt; cannot do.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;loading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are commonly used in React for props, string enums, or flexible combined types.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code tends to be cleaner and easier to read with type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example in React:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ButtonProps&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;h3&gt;
  
  
  ❗ Minor drawback of not using &lt;code&gt;interface&lt;/code&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No declaration merging:&lt;/strong&gt;
If you need to extend types from libraries (like &lt;code&gt;Express.Request&lt;/code&gt;, &lt;code&gt;NextApiRequest&lt;/code&gt;, etc.), &lt;code&gt;interface&lt;/code&gt; is advantageous because it allows multiple declarations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not suitable for classes:&lt;/strong&gt;
If you use &lt;code&gt;class implements&lt;/code&gt;, then &lt;code&gt;interface&lt;/code&gt; is required.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;🧩 However, these drawbacks rarely affect typical React app development, since most components are functional, props types are simple, and extending backend types is uncommon.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Conclusion 🎯
&lt;/h2&gt;

&lt;p&gt;Both &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;interface&lt;/code&gt; have their &lt;strong&gt;strengths&lt;/strong&gt;, but in modern React with &lt;em&gt;functional components&lt;/em&gt;, &lt;strong&gt;&lt;code&gt;type&lt;/code&gt;&lt;/strong&gt; is generally more suitable and &lt;em&gt;flexible&lt;/em&gt;. It provides &lt;strong&gt;cleaner code&lt;/strong&gt; and better support for &lt;strong&gt;unions&lt;/strong&gt;, &lt;strong&gt;intersections&lt;/strong&gt;, and &lt;strong&gt;primitive types&lt;/strong&gt;, helping you work more efficiently. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If you need &lt;strong&gt;extensible data types&lt;/strong&gt; or to work with &lt;strong&gt;classes&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;interface&lt;/code&gt;&lt;/strong&gt; is a better choice.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, the most important factor is &lt;strong&gt;consistency&lt;/strong&gt; within your &lt;strong&gt;team&lt;/strong&gt; or &lt;strong&gt;project&lt;/strong&gt;. Choosing to use &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;interface&lt;/code&gt; should follow &lt;em&gt;common guidelines&lt;/em&gt; to keep the codebase &lt;strong&gt;clear&lt;/strong&gt; and &lt;strong&gt;maintainable&lt;/strong&gt;. Finally, focus on writing &lt;strong&gt;clean&lt;/strong&gt;, &lt;strong&gt;readable&lt;/strong&gt; code and adhere to your team’s &lt;strong&gt;conventions&lt;/strong&gt; to ensure &lt;strong&gt;sustainable development&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>frontend</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Understanding Stale Closure in React: A Common Pitfall and How to Avoid It</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Thu, 22 May 2025 07:54:49 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/understanding-stale-closure-in-react-a-common-pitfall-and-how-to-avoid-it-5dih</link>
      <guid>https://forem.com/wildboar_developer/understanding-stale-closure-in-react-a-common-pitfall-and-how-to-avoid-it-5dih</guid>
      <description>&lt;h2&gt;
  
  
  🧠 1. Overview of Stale Closure in React
&lt;/h2&gt;

&lt;p&gt;In React, a common but subtle bug is the &lt;strong&gt;"stale closure"&lt;/strong&gt; — which happens when a function inside a component uses an &lt;strong&gt;outdated value&lt;/strong&gt;, not reflecting the current &lt;strong&gt;state&lt;/strong&gt; or &lt;strong&gt;props&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This often leads to unexpected behavior, especially in &lt;strong&gt;callbacks&lt;/strong&gt;, &lt;code&gt;useEffect&lt;/code&gt;, or &lt;strong&gt;asynchronous logic&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Understanding how &lt;strong&gt;JavaScript creates closures&lt;/strong&gt; and how &lt;strong&gt;React handles re-renders&lt;/strong&gt; is key to avoiding this issue.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 2. Recap: Scope &amp;amp; Closure in JavaScript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt; defines the visibility of variables. In JavaScript, we have &lt;strong&gt;function scope&lt;/strong&gt; and &lt;strong&gt;block scope&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;closure&lt;/strong&gt; occurs when a function remembers variables from the scope where it was defined, even if it's executed elsewhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// closure retains the value of count&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Closures are powerful, but in React, they can cause a function to "remember" stale values — and that’s the root of stale closures.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ 3. Common Cases of Stale Closure
&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  a. Callback inside &lt;code&gt;useEffect&lt;/code&gt; or &lt;code&gt;useCallback&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleLog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// text may be stale if not included in dependency array&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  b. Async function in event handler
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// value might be outdated&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  c. Event listeners or subscriptions
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// data might be stale&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🛠️ 4. How to Fix It
&lt;/h2&gt;

&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;br&gt;
✅ &lt;strong&gt;Use callback to update state&lt;/strong&gt;&lt;br&gt;
When updating state based on the previous state, always use a callback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// avoid setCount(count + 1)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;br&gt;
✅ &lt;strong&gt;Include variables correctly in dependency arrays&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// always use correct dependencies&lt;/span&gt;
  &lt;span class="nf"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;br&gt;
✅ &lt;strong&gt;Use &lt;code&gt;useRef&lt;/code&gt; to store the latest value&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;latestValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;latestValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;latestValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;small&gt;&lt;/small&gt;&lt;br&gt;
✅ &lt;strong&gt;Use &lt;code&gt;useEvent&lt;/code&gt; (the latest version of React or custom hook equivalent)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the newest version of React doesn't have it yet, you can create your own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cbRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cbRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;((...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;cbRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. Conclusion 🎯
&lt;/h2&gt;

&lt;p&gt;Stale closure is a natural consequence of how JavaScript handles closures and how React separates the render cycle from effects and callbacks.&lt;br&gt;&lt;br&gt;
Understanding this mechanism helps you write more stable and easier-to-debug React code.&lt;/p&gt;

&lt;p&gt;Always ask yourself:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;"At what point in time is this function using the value?"&lt;/strong&gt; — and you will avoid many bugs.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>React 19 Form Hooks vs react-hook-form: A Complete Comparison</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Thu, 22 May 2025 07:26:23 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/react-19-form-hooks-vs-react-hook-form-a-complete-comparison-34kn</link>
      <guid>https://forem.com/wildboar_developer/react-19-form-hooks-vs-react-hook-form-a-complete-comparison-34kn</guid>
      <description>&lt;h2&gt;
  
  
  🔍 1. Architecture &amp;amp; Philosophy
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;React 19 Form Hooks&lt;/th&gt;
&lt;th&gt;React Hook Form (RHF)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Paradigm&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Server-first (especially with Next.js App Router)&lt;/td&gt;
&lt;td&gt;Client-first, SPA-centric&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Form state management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Built into React via &lt;code&gt;useFormState&lt;/code&gt; and HTML form features&lt;/td&gt;
&lt;td&gt;Explicit via &lt;code&gt;useForm()&lt;/code&gt; and controlled/uncontrolled inputs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Design goal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Progressive enhancement, minimal JS&lt;/td&gt;
&lt;td&gt;Full-featured client form toolkit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Approach&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Leverages native &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; behavior and declarative actions&lt;/td&gt;
&lt;td&gt;Uses refs for performance; wraps form state with hooks and components&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  ⚙️ 2. Form Submission &amp;amp; Handling
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔸 React 19
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Server action to handle form submission&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Handle form data on server (e.g., save to DB, send email)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleAction&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SubmitButton&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;SubmitButton&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useFormStatus&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Tracks if form is submitting&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;disabled&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Submitting...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Submit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;action={}&lt;/code&gt; handles form submission — can be a server function (in frameworks like Next.js).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useFormStatus()&lt;/code&gt; can be used inside the submit button for loading states.&lt;/li&gt;
&lt;li&gt;No need for &lt;code&gt;onSubmit&lt;/code&gt;, no extra hook.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔸 React Hook Form:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useForm&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-hook-form&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Function to handle form data on submit&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Form data:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// You can send data to an API or process it here&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Enter your email"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Handles form submission using handleSubmit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requires setup of form logic explicitly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 3. Validation
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;React 19&lt;/th&gt;
&lt;th&gt;React Hook Form (RHF)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;HTML5 validation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Supported&lt;/td&gt;
&lt;td&gt;✅ Supported&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Custom validation rules&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Manual (via &lt;code&gt;onChange&lt;/code&gt;, &lt;code&gt;onBlur&lt;/code&gt;, or server validation)&lt;/td&gt;
&lt;td&gt;✅ Built-in via &lt;code&gt;rules&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Schema validation (Zod/Yup/etc.)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Manual wiring needed&lt;/td&gt;
&lt;td&gt;✅ Deep integration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Validation mode&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Limited&lt;/td&gt;
&lt;td&gt;✅ &lt;code&gt;onChange&lt;/code&gt;, &lt;code&gt;onBlur&lt;/code&gt;, &lt;code&gt;onSubmit&lt;/code&gt;, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  RHF Example with Zod:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;formState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;errors&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useForm&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;resolver&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;zodResolver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 4. Performance
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;React 19&lt;/th&gt;
&lt;th&gt;React Hook Form (RHF)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Re-renders per input&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Native browser-controlled&lt;/td&gt;
&lt;td&gt;Optimized using refs, fewer re-renders&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Controlled vs uncontrolled&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses native behavior, typically uncontrolled&lt;/td&gt;
&lt;td&gt;Prefer uncontrolled, but supports both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Form-wide state updates&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fine-grained with &lt;code&gt;useFormStatus&lt;/code&gt;, &lt;code&gt;useFormState&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Extremely performant with fine-grained updates via refs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;RHF is highly optimized to minimize re-renders even for complex forms, which is useful for dynamic field arrays or large forms.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧩 5. Complex Forms (Field Arrays, Nested Fields)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;React 19&lt;/th&gt;
&lt;th&gt;react-hook-form (RHF)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Field arrays&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Manual implementation&lt;/td&gt;
&lt;td&gt;✅ Built-in &lt;code&gt;useFieldArray()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Conditional fields&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Requires custom logic&lt;/td&gt;
&lt;td&gt;✅ Built-in handling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Dynamic inputs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Manual&lt;/td&gt;
&lt;td&gt;✅ Built-in APIs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Nested objects&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Manual (&lt;code&gt;name="user.email"&lt;/code&gt; style)&lt;/td&gt;
&lt;td&gt;✅ Deep support with dot notation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;React 19 doesn’t provide high-level utilities for these patterns — you’ll need to build your own handlers. In contrast, react-hook-form comes with battle-tested APIs designed to handle these complex scenarios smoothly.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠 6. Tooling &amp;amp; Ecosystem
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;React 19&lt;/th&gt;
&lt;th&gt;React Hook Form (RHF)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;DevTools support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Basic React DevTools&lt;/td&gt;
&lt;td&gt;✅ RHF DevTools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;UI libraries support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Minimal&lt;/td&gt;
&lt;td&gt;✅ RHF-compatible components (MUI, Chakra, shadcn-ui, etc.)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Community plugins&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;❌ Not applicable&lt;/td&gt;
&lt;td&gt;✅ RHF + Zod/Yup, i18n, async validation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TypeScript support&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Good, but verbose&lt;/td&gt;
&lt;td&gt;✅ Strong with helper types&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  📦 7. Example Comparison
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;✅ React 19 (Next.js Server Action)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// server action&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;submitForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// server-side logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;submitForm&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SubmitButton&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;SubmitButton&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useFormStatus&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;disabled&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Submitting...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Submit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ react-hook-form with Zod&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;formState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isSubmitting&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useForm&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;resolver&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;zodResolver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// client-side submit logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;disabled&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isSubmitting&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧭 When to Choose Which?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Recommended&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Simple forms with server logic&lt;/td&gt;
&lt;td&gt;✅ React 19&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Progressively enhanced apps (no JS fallback)&lt;/td&gt;
&lt;td&gt;✅ React 19&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex client-side validation&lt;/td&gt;
&lt;td&gt;✅ React Hook Form (RHF)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dynamic fields / arrays&lt;/td&gt;
&lt;td&gt;✅ React Hook Form (RHF)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full SPA, no server actions&lt;/td&gt;
&lt;td&gt;✅ React Hook Form (RHF)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You're using Next.js App Router&lt;/td&gt;
&lt;td&gt;✅ React 19 (with optional RHF)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧠 TL;DR
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature/Need&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;React 19&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;react-hook-form&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Simple forms&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complex logic&lt;/td&gt;
&lt;td&gt;❌ Manual&lt;/td&gt;
&lt;td&gt;✅ Built-in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server-first architecture&lt;/td&gt;
&lt;td&gt;✅ Built-in support&lt;/td&gt;
&lt;td&gt;❌ Requires workarounds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema validation&lt;/td&gt;
&lt;td&gt;❌ Manual&lt;/td&gt;
&lt;td&gt;✅ Zod/Yup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dynamic fields (arrays, etc.)&lt;/td&gt;
&lt;td&gt;❌ Tedious&lt;/td&gt;
&lt;td&gt;✅ Easy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fallback without JS&lt;/td&gt;
&lt;td&gt;✅ Native support&lt;/td&gt;
&lt;td&gt;❌ JS-dependent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TypeScript experience&lt;/td&gt;
&lt;td&gt;✅ Good&lt;/td&gt;
&lt;td&gt;✅ Excellent&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Conclusion 🎯
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React 19’s native form hooks&lt;/strong&gt; and &lt;strong&gt;react-hook-form&lt;/strong&gt; both make building forms easier—but they shine in different situations.&lt;/p&gt;

&lt;p&gt;Use &lt;strong&gt;React 19 form hooks&lt;/strong&gt; if you want &lt;strong&gt;simple forms&lt;/strong&gt; that work well with &lt;strong&gt;server-side actions&lt;/strong&gt; and need &lt;strong&gt;fewer dependencies&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Use &lt;strong&gt;react-hook-form&lt;/strong&gt; if your forms need &lt;strong&gt;lots of validation, dynamic fields, or complex behavior on the client side&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes, you can even use &lt;strong&gt;both together&lt;/strong&gt; depending on your app’s needs. Knowing when to use each will help you build &lt;strong&gt;better forms with React&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>javascript</category>
      <category>analytics</category>
    </item>
    <item>
      <title>Introducing Zod 4 – Super Fast, Lightweight, and Packed with Powerful Features!</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Thu, 22 May 2025 02:45:24 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg</link>
      <guid>https://forem.com/wildboar_developer/introducing-zod-4-super-fast-lightweight-and-packed-with-powerful-features-4fkg</guid>
      <description>&lt;p&gt;After a year of active development, Zod 4 is officially released with major improvements. This stable version is faster, slimmer, and more TypeScript-optimized compared to the previous Zod 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlights of Zod 4
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🚀 Outstanding Performance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;14x faster string parsing:&lt;/strong&gt; Deep optimizations in string validation make your app respond much faster, especially when handling large amounts of text data.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;7x faster array parsing:&lt;/strong&gt; Efficiently process complex or large arrays, minimizing latency in data validation.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;6.5x faster object parsing:&lt;/strong&gt; Ideal for objects with many fields, ensuring smoother validation and faster API responses.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ TypeScript Compiler Optimization
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reduces type instantiations by up to &lt;strong&gt;100x&lt;/strong&gt;, speeding up the TypeScript compiler significantly, especially for large and complex codebases.
&lt;/li&gt;
&lt;li&gt;Compilation time is improved by around &lt;strong&gt;10x&lt;/strong&gt; compared to Zod 3, providing a smoother developer experience and faster editor feedback.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📦 Reduced Bundle Size
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Core bundle size is &lt;strong&gt;2.3x smaller&lt;/strong&gt; than Zod 3, making your applications lighter and faster to load.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;zod/v4-mini&lt;/code&gt; variant is even lighter (~1.88KB gzip), using a functional API optimized for &lt;strong&gt;tree-shaking&lt;/strong&gt;, perfect for projects with strict bundle size limits.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🏷️ Powerful Metadata System
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Allows attaching strongly-typed metadata to schemas, enabling easy mapping to standard JSON Schema.
&lt;/li&gt;
&lt;li&gt;Great for automation tools, API documentation, and data transformation workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔄 Simple Recursive and Mutually Recursive Types
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Define self-referencing or mutually referencing types (e.g., category trees, user-post relationships) directly without complex casting hacks.
&lt;/li&gt;
&lt;li&gt;Increases code clarity and maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🌐 Internationalized Error API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Supports a &lt;strong&gt;locales&lt;/strong&gt; system to translate error messages into multiple languages, improving user experience in global applications.
&lt;/li&gt;
&lt;li&gt;English locale available now, with community contributions expected for more languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✨ New Top-Level String Format APIs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Popular formats like &lt;code&gt;email()&lt;/code&gt;, &lt;code&gt;uuid()&lt;/code&gt;, &lt;code&gt;ip()&lt;/code&gt;, and &lt;code&gt;url()&lt;/code&gt; are now top-level functions, leading to cleaner code and better tree-shaking.
&lt;/li&gt;
&lt;li&gt;Older method-based APIs on strings remain available but are deprecated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔤 &lt;code&gt;z.stringbool()&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Converts strings to booleans using a flexible, environment-variable style (e.g., &lt;code&gt;"true"&lt;/code&gt;, &lt;code&gt;"yes"&lt;/code&gt;, &lt;code&gt;"1"&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt;; &lt;code&gt;"false"&lt;/code&gt;, &lt;code&gt;"no"&lt;/code&gt;, &lt;code&gt;"0"&lt;/code&gt; → &lt;code&gt;false&lt;/code&gt;).
&lt;/li&gt;
&lt;li&gt;Customizable truthy/falsy values to fit your specific needs, making it easy to validate boolean-like string inputs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🎯 Simplified Error Customization API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Unifies various error customization approaches into a single &lt;code&gt;error&lt;/code&gt; parameter, which can be a string or function, enabling concise and clear error definitions.
&lt;/li&gt;
&lt;li&gt;Reduces complexity and confusion when writing validations and handling errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔀 More Powerful Discriminated Unions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Supports multiple schema types as discriminators, including unions, pipes, and nested objects.
&lt;/li&gt;
&lt;li&gt;Allows creating complex and maintainable type classifications for diverse data structures.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔧 &lt;code&gt;.overwrite()&lt;/code&gt; Method
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Alternative to &lt;code&gt;.transform()&lt;/code&gt; for applying data transformations &lt;strong&gt;without changing the inferred type&lt;/strong&gt;, preserving type information.
&lt;/li&gt;
&lt;li&gt;Useful for simple data manipulation without breaking compatibility with JSON Schema or inferred types.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🧩 Zod Mini
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;super lightweight&lt;/strong&gt; functional API variant that removes excess methods to optimize tree-shaking, resulting in very small final bundles.
&lt;/li&gt;
&lt;li&gt;Perfect for front-end apps needing minimal download sizes while still using Zod for validation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🚀 Conclusion
&lt;/h3&gt;

&lt;p&gt;Zod 4 marks a significant advancement in TypeScript schema validation, offering enhanced performance, reduced bundle sizes, and a more intuitive API. With features like improved TypeScript compiler efficiency, a powerful metadata system, and streamlined error handling, Zod 4 is designed to meet the needs of modern development.&lt;/p&gt;

&lt;p&gt;For comprehensive documentation, including guides on defining schemas, customizing errors, and integrating with JSON Schema, visit the official Zod 4 documentation: &lt;a href="https://zod.dev/v4" rel="noopener noreferrer"&gt;https://zod.dev/v4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy coding! 😊&lt;/p&gt;

</description>
      <category>news</category>
      <category>javascript</category>
      <category>learning</category>
    </item>
    <item>
      <title>Why Frontend Developers Need to Know Docker?</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Wed, 21 May 2025 10:00:03 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/why-frontend-developers-need-to-know-docker-3e05</link>
      <guid>https://forem.com/wildboar_developer/why-frontend-developers-need-to-know-docker-3e05</guid>
      <description>&lt;h2&gt;
  
  
  1. What is Docker?
&lt;/h2&gt;

&lt;p&gt;Docker is a software platform that allows you to create and run applications inside &lt;strong&gt;containers&lt;/strong&gt; — lightweight environments packaging all necessary components like source code, libraries, runtime, and configurations to ensure the application runs consistently on any machine.  &lt;/p&gt;

&lt;p&gt;Unlike traditional virtual machines, Docker containers share the host OS kernel but isolate the application environment, making them fast, lightweight, and easy to deploy. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. How Does Docker Help Frontend Developers?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistent development environment:&lt;/strong&gt; Avoid the “it works on my machine but not on yours” problem by packaging the entire frontend environment into a container. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplified build and deployment:&lt;/strong&gt; Docker helps build frontend apps (React, Next.js, Vue...) and run them on a standardized environment, minimizing errors during server or cloud deployment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy collaboration with backend:&lt;/strong&gt; When working with backend APIs, Docker allows running frontend and backend simultaneously in separate containers, simplifying management and overall testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supports CI/CD pipelines:&lt;/strong&gt; Docker enables building and testing frontend apps in identical environments, ensuring quality and speeding up deployment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Saves setup time:&lt;/strong&gt; No need to manually install many tools — just run a container with a ready environment for development or demo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. How Deep Should Frontend Developers Know Docker?
&lt;/h2&gt;

&lt;p&gt;Frontend developers don’t need to master every Docker feature like backend or devops engineers but should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clearly understand &lt;strong&gt;what containers and Docker are&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Know how to &lt;strong&gt;write a simple Dockerfile&lt;/strong&gt; to build and run frontend apps. &lt;/li&gt;
&lt;li&gt;Use commands like &lt;code&gt;docker build&lt;/code&gt;, &lt;code&gt;docker run&lt;/code&gt; to test apps locally.&lt;/li&gt;
&lt;li&gt;Understand &lt;strong&gt;mounting volumes and exposing ports&lt;/strong&gt; for smooth development. &lt;/li&gt;
&lt;li&gt;Be able to use &lt;strong&gt;basic Docker Compose&lt;/strong&gt; when coordinating multiple services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No need to dive deep into Docker networking, clustering, or advanced optimizations unless directly working with backend or devops.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Example: Creating a Next.js App and Dockerizing It
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before you start, ensure &lt;strong&gt;Docker is installed and running on your machine&lt;/strong&gt;.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Windows or Mac, download Docker Desktop at &lt;a href="https://docs.docker.com/desktop/" rel="noopener noreferrer"&gt;https://docs.docker.com/desktop/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;For Linux, follow installation instructions at &lt;a href="https://docs.docker.com/engine/install/" rel="noopener noreferrer"&gt;https://docs.docker.com/engine/install/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check Docker installation with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 1: Create a Next.js app
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app my-next-app
&lt;span class="nb"&gt;cd &lt;/span&gt;my-next-app
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Write a Dockerfile
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;Dockerfile&lt;/code&gt; in your project folder with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Build stage&lt;/span&gt;
&lt;span class="c"&gt;# syntax=docker.io/docker/dockerfile:1&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;node:18-alpine&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies only when needed&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;deps&lt;/span&gt;
&lt;span class="c"&gt;# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apk add &lt;span class="nt"&gt;--no-cache&lt;/span&gt; libc6-compat
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies based on the preferred package manager&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; yarn.lock &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;yarn &lt;span class="nt"&gt;--frozen-lockfile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package-lock.json &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;npm ci&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; pnpm-lock.yaml &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;corepack &lt;span class="nb"&gt;enable &lt;/span&gt;pnpm &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pnpm i &lt;span class="nt"&gt;--frozen-lockfile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;else &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Lockfile not found."&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;exit &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;fi&lt;/span&gt;


&lt;span class="c"&gt;# Rebuild the source code only when needed&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;builder&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=deps /app/node_modules ./node_modules&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="c"&gt;# Next.js collects completely anonymous telemetry data about general usage.&lt;/span&gt;
&lt;span class="c"&gt;# Learn more here: https://nextjs.org/telemetry&lt;/span&gt;
&lt;span class="c"&gt;# Uncomment the following line in case you want to disable telemetry during the build.&lt;/span&gt;
&lt;span class="c"&gt;# ENV NEXT_TELEMETRY_DISABLED=1&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; yarn.lock &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;yarn run build&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; package-lock.json &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;npm run build&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; pnpm-lock.yaml &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;corepack &lt;span class="nb"&gt;enable &lt;/span&gt;pnpm &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pnpm run build&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;else &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Lockfile not found."&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;exit &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\
&lt;/span&gt;  &lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# Production image, copy all the files and run next&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;base&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;runner&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; NODE_ENV=production&lt;/span&gt;
&lt;span class="c"&gt;# Uncomment the following line in case you want to disable telemetry during runtime.&lt;/span&gt;
&lt;span class="c"&gt;# ENV NEXT_TELEMETRY_DISABLED=1&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;addgroup &lt;span class="nt"&gt;--system&lt;/span&gt; &lt;span class="nt"&gt;--gid&lt;/span&gt; 1001 nodejs
&lt;span class="k"&gt;RUN &lt;/span&gt;adduser &lt;span class="nt"&gt;--system&lt;/span&gt; &lt;span class="nt"&gt;--uid&lt;/span&gt; 1001 nextjs

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=builder /app/public ./public&lt;/span&gt;

&lt;span class="c"&gt;# Automatically leverage output traces to reduce image size&lt;/span&gt;
&lt;span class="c"&gt;# https://nextjs.org/docs/advanced-features/output-file-tracing&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=builder --chown=nextjs:nodejs /app/.next/standalone ./&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static&lt;/span&gt;

&lt;span class="k"&gt;USER&lt;/span&gt;&lt;span class="s"&gt; nextjs&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 3000&lt;/span&gt;

&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; PORT=3000&lt;/span&gt;

&lt;span class="c"&gt;# server.js is created by next build from the standalone output&lt;/span&gt;
&lt;span class="c"&gt;# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; HOSTNAME="0.0.0.0"&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["node", "server.js"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Build and run the container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; my-next-app &lt;span class="nb"&gt;.&lt;/span&gt;
docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 3000:3000 my-next-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your browser and go to &lt;code&gt;http://localhost:3000&lt;/code&gt; to see your Next.js app running inside the Docker container.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Conclusion 🎯
&lt;/h2&gt;

&lt;p&gt;Docker is no longer just a tool for backend or devops — it’s becoming essential for frontend developers too. Knowing how to use Docker helps frontend devs work more professionally, synchronize development environments, and accelerate build, test, and deployment processes.&lt;/p&gt;

&lt;p&gt;While deep expertise isn’t required, mastering basic Docker skills is a great advantage for any frontend developer wanting to expand their skillset and collaborate effectively in multi-team projects.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>docker</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Stop Hesitating, Just Use React Or Any Modern Framework</title>
      <dc:creator>Wild Boar Dev</dc:creator>
      <pubDate>Wed, 21 May 2025 02:22:21 +0000</pubDate>
      <link>https://forem.com/wildboar_developer/stop-hesitating-just-use-react-or-any-modern-framework-5h84</link>
      <guid>https://forem.com/wildboar_developer/stop-hesitating-just-use-react-or-any-modern-framework-5h84</guid>
      <description>&lt;h2&gt;
  
  
  Why does it matter?
&lt;/h2&gt;

&lt;p&gt;The web today is no longer just a collection of simple static pages. It’s where businesses run, communities connect, and complex interactions happen. If you still think plain HTML and a few lines of manual JS are enough, you’re limiting yourself and your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  What plain HTML can’t do but frameworks can
&lt;/h2&gt;

&lt;p&gt;You might be proud of &lt;code&gt;&amp;lt;details&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;dialog&amp;gt;&lt;/code&gt;, or basic forms. But building an app with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complex interactive UI&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Frameworks handle dynamic interactions like modals, tabs, accordions, and tooltips that would require verbose JavaScript and DOM manipulation in plain HTML.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Multi-dimensional user state management&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Plain HTML has no native support &lt;strong&gt;built-in state&lt;/strong&gt;, &lt;strong&gt;components&lt;/strong&gt;, &lt;strong&gt;context/shared state&lt;/strong&gt;, ... But, tools like React’s &lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useReducer&lt;/code&gt;, or context APIs help manage complex app logic across components.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Real-time data updates&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Frameworks make it easier to connect with APIs and WebSockets to update the UI in real-time without reloading the page.&lt;br&gt;
→ Plus, re-rendering with React's state is much easier and cleaner than manually selecting elements with document.querySelector() and updating the DOM yourself.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Reusable, maintainable components&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Component-based architecture allows you to build self-contained, testable, and reusable UI elements—plain HTML offers no such modularization.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;And proper accessibility for all users&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Frameworks provide powerful ways to manage ARIA attributes, keyboard navigation, and focus control dynamically, supporting a fully accessible experience out-of-the-box. Like this example:&lt;/em&gt;&lt;/p&gt;


&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;aria-expanded&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Menu&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The &lt;code&gt;aria-expanded&lt;/code&gt; updates automatically as &lt;code&gt;isOpen&lt;/code&gt; changes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 Frameworks like React are powerful tools that help you handle all that complexity easily instead of wrestling with tons of manual DOM manipulation.&lt;/p&gt;

&lt;h2&gt;
  
  
  State management — the core of every modern app
&lt;/h2&gt;

&lt;p&gt;Trying to manage state with global variables or direct DOM manipulation will only make your code messy and fragile. Frameworks provide clear state management systems that keep your app stable and scalable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reusable components — reduce duplication, boost productivity
&lt;/h2&gt;

&lt;p&gt;Instead of copying and pasting HTML everywhere and fixing things in dozens of places, React lets you create reusable components. Change once, update everywhere. Keep your code clean, readable, and maintainable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Smarter UI updates for better performance
&lt;/h2&gt;

&lt;p&gt;No more manually tweaking every element when data changes. Frameworks optimize rendering to update only what’s necessary, making your app smooth and avoiding display bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessibility — done right
&lt;/h2&gt;

&lt;p&gt;Building interfaces that work for everyone, including users relying on assistive technologies, requires high technical standards that plain HTML can’t easily meet. Frameworks help you create components with built-in ARIA attributes, keyboard navigation, and all the essentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Developer experience matters too!
&lt;/h2&gt;

&lt;p&gt;React and its tools help you develop faster with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hot reloads on code changes
&lt;/li&gt;
&lt;li&gt;Early error detection via TypeScript
&lt;/li&gt;
&lt;li&gt;Rich ecosystem of libraries
&lt;/li&gt;
&lt;li&gt;Effective debugging, avoiding browser quirks
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Performance isn’t just about initial load speed
&lt;/h2&gt;

&lt;p&gt;Complex apps need to feel responsive in every interaction. Modern frameworks, combined with server-side rendering, code splitting, and lazy loading, handle this perfectly.&lt;/p&gt;

&lt;h2&gt;
  
  
  When should you use React?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Your app has complex dynamic state to manage
&lt;/li&gt;
&lt;li&gt;You need to build complex UI with reusable components
&lt;/li&gt;
&lt;li&gt;It’s a SPA or web app, not just a static site
&lt;/li&gt;
&lt;li&gt;You work in a team and need clear structure
&lt;/li&gt;
&lt;li&gt;You want to leverage existing tools and libraries
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Don’t fear the tool
&lt;/h2&gt;

&lt;p&gt;Frameworks are just tools; the user is the real factor. Used right, they solve tons of problems. Used wrong, they can cause headaches. But avoiding powerful tools just because you “fear complexity” will only slow you down and cause more frustration.&lt;/p&gt;




&lt;p&gt;In short: If you want to build modern, interactive web apps, don’t avoid React or similar frameworks. They’re the way to work efficiently and keep your code clean and maintainable.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
