<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Farhan Khan</title>
    <description>The latest articles on DEV Community by Farhan Khan (@fluffsce).</description>
    <link>https://dev.to/fluffsce</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%2F3445387%2F9c11cc63-00df-4a3e-a23a-1cb3dcb84635.jpg</url>
      <title>DEV Community: Farhan Khan</title>
      <link>https://dev.to/fluffsce</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fluffsce"/>
    <language>en</language>
    <item>
      <title>An overlooked React idea that finally made everything make sense.</title>
      <dc:creator>Farhan Khan</dc:creator>
      <pubDate>Tue, 16 Dec 2025 15:56:40 +0000</pubDate>
      <link>https://dev.to/fluffsce/an-overlooked-react-idea-that-finally-made-everything-make-sense-58fi</link>
      <guid>https://dev.to/fluffsce/an-overlooked-react-idea-that-finally-made-everything-make-sense-58fi</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/fluffsce" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F3445387%2F9c11cc63-00df-4a3e-a23a-1cb3dcb84635.jpg" alt="fluffsce"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/fluffsce/react-state-immutability-and-why-mutating-stuff-feels-like-hugging-someone-elses-wife-4566" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;React State, Immutability, and Why Mutating Stuff Feels Like Hugging Someone Else’s Wife&lt;/h2&gt;
      &lt;h3&gt;Farhan Khan ・ Dec 16&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>react</category>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React State, Immutability, and Why Mutating Stuff Feels Like Hugging Someone Else’s Wife</title>
      <dc:creator>Farhan Khan</dc:creator>
      <pubDate>Tue, 16 Dec 2025 15:53:09 +0000</pubDate>
      <link>https://dev.to/fluffsce/react-state-immutability-and-why-mutating-stuff-feels-like-hugging-someone-elses-wife-4566</link>
      <guid>https://dev.to/fluffsce/react-state-immutability-and-why-mutating-stuff-feels-like-hugging-someone-elses-wife-4566</guid>
      <description>&lt;p&gt;I was learning React (FullStackOpen - very good resource) and something &lt;em&gt;clicked&lt;/em&gt; so hard that I got mad nobody talks about how insanely cool this actually is (I too overlooked it for the longest while....).&lt;/p&gt;

&lt;p&gt;We're told:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;don't mutate state
&lt;/li&gt;
&lt;li&gt;always create a new object
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cool. But....&lt;br&gt;
&lt;em&gt;why does this feel so correct once you get it?&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  State is the one real thing
&lt;/h3&gt;

&lt;p&gt;State is the &lt;strong&gt;single authoritative piece&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The UI isn't alive. It's just a reflection React rebuilds from state. There is one &lt;strong&gt;real&lt;/strong&gt; state. Everything else is just a copy or a projection.&lt;/p&gt;

&lt;p&gt;Conceptually, React treats the UI as disposable and re-runs the render tree. &lt;/p&gt;


&lt;h3&gt;
  
  
  Mutable state is a horror story
&lt;/h3&gt;

&lt;p&gt;Imagine one shared object on the heap. Everyone has access.&lt;/p&gt;

&lt;p&gt;Someone does this:&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;clicks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Now what?&lt;br&gt;
Who touched it?&lt;br&gt;
When?&lt;br&gt;
From where?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The heap turns into a crime scene.&lt;/p&gt;

&lt;p&gt;It's like walking into a neighborhood where every house looks the same, entering the wrong one, and hugging someone else's wife.&lt;/p&gt;

&lt;p&gt;You saw the same Christmas tree in the yard and said "Yep my house".&lt;br&gt;
&lt;em&gt;That's shared mutable state.&lt;/em&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Immutability fixes this
&lt;/h3&gt;

&lt;p&gt;Now compare that to this:&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="nf"&gt;setClicks&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You are &lt;strong&gt;not&lt;/strong&gt; modifying the old object.&lt;/p&gt;

&lt;p&gt;You are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;leaving the old one untouched&lt;/li&gt;
&lt;li&gt;creating a brand new object&lt;/li&gt;
&lt;li&gt;giving React a new reference&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anyone still holding the old reference sees the old reality. No surprises. No silent corruption.&lt;/p&gt;

&lt;p&gt;React doesn't check what &lt;em&gt;changed&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
It checks &lt;strong&gt;whether it's the same thing or not&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Same reference → nothing happens&lt;br&gt;&lt;br&gt;
New reference → re-render everything.&lt;br&gt;
Sounds simple indeed!&lt;/p&gt;


&lt;h3&gt;
  
  
  "But where is &lt;code&gt;newClicks&lt;/code&gt;?"
&lt;/h3&gt;

&lt;p&gt;This is where I got confused (I know ... "Omg its so simple yada yada.. HUSH!) anways-&lt;/p&gt;

&lt;p&gt;When you write:&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="nf"&gt;setClicks&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You &lt;strong&gt;did&lt;/strong&gt; create &lt;code&gt;newClicks&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You just didn't name it.&lt;/p&gt;

&lt;p&gt;Objects don't need variable names to exist.&lt;br&gt;&lt;br&gt;
They just need to be created and passed once.&lt;/p&gt;

&lt;p&gt;The object is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;allocated in memory&lt;/li&gt;
&lt;li&gt;passed to &lt;code&gt;setClicks&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;compared by React&lt;/li&gt;
&lt;li&gt;later garbage-collected when nobody references it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same deal with arrow functions.&lt;/p&gt;

&lt;p&gt;Yes, there can be hundreds of these "anonymous" objects and functions.&lt;/p&gt;

&lt;p&gt;And the browser just calmly says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cool, I'll clean it up later&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Garbage collection is doing god-tier work in the background.&lt;/p&gt;




&lt;h3&gt;
  
  
  React didn't invent this. They just used it perfectly
&lt;/h3&gt;

&lt;p&gt;The real credit goes to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lambda calculus
&lt;/li&gt;
&lt;li&gt;first-class functions
&lt;/li&gt;
&lt;li&gt;garbage collection
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React just had the audacity to say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;let's build a UI assuming everything is disposable&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;UI = pure function of state.&lt;br&gt;&lt;br&gt;
Re-run it, throw it away. REPEAT.&lt;br&gt;
Turns out computers are fast :) and we are bad at tracking mutability just like how we are bad at coding. &lt;/p&gt;




&lt;h3&gt;
  
  
  Final thought
&lt;/h3&gt;

&lt;p&gt;Immutability isn't about elegance. It's about &lt;strong&gt;knowing where the hell you are&lt;/strong&gt;.&lt;/p&gt;

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