<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CristianScript on Medium]]></title>
        <description><![CDATA[Stories by CristianScript on Medium]]></description>
        <link>https://medium.com/@chris191919torres?source=rss-aa8b9157038e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CsBjyw69rgGPI5M4jO7Y-g.jpeg</url>
            <title>Stories by CristianScript on Medium</title>
            <link>https://medium.com/@chris191919torres?source=rss-aa8b9157038e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:53:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chris191919torres/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Reconciliation: Why Your Component Suddenly Forgot Everything]]></title>
            <link>https://medium.com/@chris191919torres/react-reconciliation-why-your-component-suddenly-forgot-everything-1970bb6bbaa0?source=rss-aa8b9157038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1970bb6bbaa0</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[CristianScript]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 02:16:06 GMT</pubDate>
            <atom:updated>2026-08-11T02:16:06.296Z</atom:updated>
            <content:encoded><![CDATA[<p>You have a form.</p><p>The user types their name.</p><p>Everything works.</p><p>Then some innocent-looking conditional changes:</p><pre>{isAdmin ? &lt;AdminPanel /&gt; : &lt;UserPanel /&gt;}</pre><p>And suddenly:</p><ul><li>an input resets</li><li>local state disappears</li><li>an animation starts over</li><li>a useEffect runs again</li><li>your carefully constructed component behaves like it has never existed before</li></ul><p>You stare at React DevTools.</p><p>You stare at the code.</p><p>You add a console.log.</p><p>Then seventeen more console.logs.</p><p>Eventually you reach the conclusion every developer reaches at least once:</p><p>“React randomly remounted my component.”</p><p>Except React didn’t randomly do anything.</p><p>React is actually following a surprisingly small set of rules.</p><p>The problem is that most developers learn reconciliation as:</p><p>“React compares the old Virtual DOM with the new Virtual DOM.”</p><p>Technically useful.</p><p>Practically almost useless.</p><p>Because the question you actually care about when debugging is:</p><p><strong>How does React decide whether something in the new render is the SAME thing that existed in the previous render?</strong></p><p>That question explains state preservation, remounting, keys, list bugs, disappearing input values, and a surprising number of React problems that initially look completely unrelated.</p><p>So let’s answer it.</p><h3>React Has an Identity Problem</h3><p>Consider:</p><pre>function Counter() {<br>  const [count, setCount] = useState(0)</pre><pre>return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      {count}<br>    &lt;/button&gt;<br>  )<br>}</pre><p>Now render it:</p><pre>&lt;Counter /&gt;</pre><p>Click until:</p><pre>count = 5</pre><p>Then something causes the parent to render again.</p><p>The parent produces another:</p><pre>&lt;Counter /&gt;</pre><p>Here’s something that initially feels strange:</p><p><strong>That’s a new React element object.</strong></p><p>Render #1 conceptually produced:</p><pre>{<br>  type: Counter,<br>  props: {}<br>}</pre><p>Render #2 produces another object:</p><pre>{<br>  type: Counter,<br>  props: {}<br>}</pre><p>Those objects aren’t reference-equal.</p><p>Conceptually:</p><pre>Object.is(oldElement, newElement)<br>// false</pre><p>And yet the counter doesn’t reset.</p><p>It stays:</p><pre>5</pre><p>Why?</p><p>Because React does <strong>not</strong> define component identity by React-element object identity.</p><p>That’s the first major idea.</p><p>React elements are descriptions.</p><p>React expects you to create new descriptions every render.</p><p>React’s job is to figure out whether the new description corresponds to something that already exists.</p><h3>The Question React Is Really Asking</h3><p>Imagine the old rendered tree contains:</p><pre>&lt;Counter /&gt;</pre><p>and the next render also contains:</p><pre>&lt;Counter /&gt;</pre><p>React is essentially asking:</p><p>“Does this new element correspond to the component that was already here?”</p><p>Several things matter, especially:</p><pre>POSITION<br>TYPE<br>KEY</pre><p>This is a much better mental model than:</p><p>“React compares objects.”</p><p>React is reconciling <strong>identity across renders</strong>.</p><h3>Position: Where Are You in the Tree?</h3><p>Start with:</p><pre>function App() {<br>  return (<br>    &lt;main&gt;<br>      &lt;Counter /&gt;<br>    &lt;/main&gt;<br>  )<br>}</pre><p>React has something conceptually like:</p><pre>App<br> │<br> main<br> │<br> Counter</pre><p>Now App renders again:</p><pre>function App() {<br>  return (<br>    &lt;main&gt;<br>      &lt;Counter /&gt;<br>    &lt;/main&gt;<br>  )<br>}</pre><p>Same component type.</p><p>Same corresponding position.</p><p>React can associate the new Counter element with the existing Counter Fiber.</p><p>So state survives.</p><pre>RENDER #1</pre><pre>main<br> └── Counter<br>       count = 5</pre><pre>RENDER #2</pre><pre>main<br> └── Counter<br>       count = 5</pre><p>The element object is new.</p><p>The component identity is preserved.</p><p>That’s why this is wrong:</p><pre>new React Element<br>      =<br>new component instance</pre><p>No.</p><p>React elements are constantly recreated.</p><p>What matters is whether React can reconcile the new description with existing work.</p><h3>Type: Are You Still the Same Kind of Thing?</h3><p>Now let’s make one tiny change.</p><p>Render #1:</p><pre>&lt;Counter /&gt;</pre><p>Render #2:</p><pre>&lt;Message /&gt;</pre><p>Conceptually:</p><pre>OLD<br>type: Counter</pre><pre>NEW<br>type: Message</pre><p>React sees:</p><pre>Counter !== Message</pre><p>This is not the same component type.</p><p>So React can’t simply preserve the old Counter as if nothing happened.</p><p>The old subtree is removed.</p><p>A new one is mounted.</p><p>Which means Counter’s local state disappears with it.</p><pre>Counter<br>count = 5<br>   │<br>   │ type changed<br>   ▼<br>Message<br>new component<br>new state<br>new lifecycle</pre><p>This is why component type matters so much during reconciliation.</p><h3>Host Elements Follow the Same Basic Idea</h3><p>Suppose one render produces:</p><pre>&lt;div&gt;<br>  Hello<br>&lt;/div&gt;</pre><p>and the next:</p><pre>&lt;div&gt;<br>  Goodbye<br>&lt;/div&gt;</pre><p>Same host type:</p><pre>&quot;div&quot; → &quot;div&quot;</pre><p>React can keep the existing DOM element and update what’s necessary.</p><p>But:</p><pre>&lt;div&gt;Hello&lt;/div&gt;</pre><p>becoming:</p><pre>&lt;section&gt;Hello&lt;/section&gt;</pre><p>means:</p><pre>&quot;div&quot; → &quot;section&quot;</pre><p>Different host type.</p><p>React generally replaces that host subtree rather than pretending a &lt;div&gt; somehow became a &lt;section&gt;.</p><p>This is why the React element’s type property isn’t some boring metadata field.</p><p>It’s part of how React understands identity.</p><h3>Then Keys Walk Into the Room</h3><p>Now we reach one of React’s most misunderstood features:</p><pre>key</pre><p>Most developers initially learn:</p><p>“You need keys when using .map() or React gives you a warning.”</p><p>True.</p><p>Also completely undersells what keys are doing.</p><p>Keys aren’t there to make the warning disappear.</p><p>Keys help React understand <strong>identity among siblings</strong>.</p><p>Consider:</p><pre>const users = [<br>  { id: 1, name: &quot;Alice&quot; },<br>  { id: 2, name: &quot;Bob&quot; },<br>  { id: 3, name: &quot;Charlie&quot; }<br>]</pre><p>You render:</p><pre>users.map(user =&gt; (<br>  &lt;User<br>    key={user.id}<br>    user={user}<br>  /&gt;<br>))</pre><p>React conceptually sees sibling identities like:</p><pre>User key=1<br>User key=2<br>User key=3</pre><p>Now reorder them:</p><pre>User key=3<br>User key=1<br>User key=2</pre><p>React can reason:</p><p>“Ah. 3 didn’t disappear. It moved.”</p><p>“1 is still here.”</p><p>“2 is still here too.”</p><p>That’s what stable keys buy you.</p><p>Identity across sibling reordering.</p><h3>Why Array Index Keys Can Betray You</h3><p>Now let’s do the thing React developers have been warned about since approximately the invention of electricity:</p><pre>users.map((user, index) =&gt; (<br>  &lt;User<br>    key={index}<br>    user={user}<br>  /&gt;<br>))</pre><p>Suppose we have:</p><pre>index 0 → Alice<br>index 1 → Bob<br>index 2 → Charlie</pre><p>React effectively associates:</p><pre>key 0 → Alice<br>key 1 → Bob<br>key 2 → Charlie</pre><p>Now Alice gets removed.</p><p>Your array becomes:</p><pre>index 0 → Bob<br>index 1 → Charlie</pre><p>But look at the identities React receives:</p><pre>BEFORE</pre><pre>key 0 → Alice<br>key 1 → Bob<br>key 2 → Charlie</pre><pre>AFTER</pre><pre>key 0 → Bob<br>key 1 → Charlie</pre><p>React sees:</p><pre>key 0 still exists<br>key 1 still exists</pre><p>But <em>you changed which user those keys represent</em>.</p><p>You basically told React:</p><p>“Bob is Alice now.”</p><p>React isn’t psychic.</p><p>It trusts the identity information you provided.</p><p>And this is where hilarious bugs begin.</p><h3>The Input Bug That Makes Keys Finally Click</h3><p>Imagine:</p><pre>function User({ user }) {<br>  const [note, setNote] = useState(&quot;&quot;)</pre><pre>return (<br>    &lt;div&gt;<br>      &lt;strong&gt;{user.name}&lt;/strong&gt;</pre><pre>&lt;input<br>        value={note}<br>        onChange={e =&gt; setNote(e.target.value)}<br>      /&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>You render:</p><pre>users.map((user, index) =&gt; (<br>  &lt;User<br>    key={index}<br>    user={user}<br>  /&gt;<br>))</pre><p>Suppose you type:</p><pre>Alice   → &quot;Call tomorrow&quot;<br>Bob     → &quot;&quot;<br>Charlie → &quot;&quot;</pre><p>Then Alice gets deleted.</p><p>Because you used indexes:</p><pre>BEFORE</pre><pre>key 0 → Alice<br>         state: &quot;Call tomorrow&quot;</pre><pre>key 1 → Bob<br>         state: &quot;&quot;</pre><pre>key 2 → Charlie<br>         state: &quot;&quot;</pre><p>After deleting Alice:</p><pre>AFTER</pre><pre>key 0 → Bob<br>key 1 → Charlie</pre><p>React sees key 0 and thinks:</p><p>“I already have the component at identity 0.”</p><p>So Bob can inherit the state associated with what used to represent Alice.</p><p>Suddenly:</p><pre>Bob<br>[ Call tomorrow ]</pre><p>And now your bug report says:</p><p>“Input values randomly move between users.”</p><p>They didn’t randomly move.</p><p>Your keys lied.</p><p>Use:</p><pre>key={user.id}</pre><p>and React gets:</p><pre>BEFORE</pre><pre>Alice   → key 42<br>Bob     → key 81<br>Charlie → key 97</pre><pre>AFTER</pre><pre>Bob     → key 81<br>Charlie → key 97</pre><p>Now React understands exactly who disappeared.</p><p>Alice.</p><p>Bob is still Bob.</p><p>Charlie is still Charlie.</p><p>Nobody wakes up with someone else’s state.</p><h3>Keys Aren’t Only for .map()</h3><p>This is where keys become much more interesting.</p><p>Consider:</p><pre>function App() {<br>  const [user, setUser] = useState(alice)</pre><pre>return &lt;Profile user={user} /&gt;<br>}</pre><p>Suppose Profile has internal state:</p><pre>function Profile({ user }) {<br>  const [comment, setComment] = useState(&quot;&quot;)</pre><pre>// ...<br>}</pre><p>Switch:</p><pre>Alice → Bob</pre><p>But you’re still rendering:</p><pre>&lt;Profile user={user} /&gt;</pre><p>Same position.</p><p>Same type.</p><p>No key distinguishing the users.</p><p>React sees:</p><pre>Profile → Profile</pre><p>So the component identity is preserved.</p><p>That means the local comment state can also be preserved.</p><p>Sometimes that’s exactly what you want.</p><p>Sometimes it’s absolutely not.</p><p>If each user’s profile should be considered a fresh component identity, you can say:</p><pre>&lt;Profile<br>  key={user.id}<br>  user={user}<br>/&gt;</pre><p>Now:</p><pre>Alice</pre><pre>Profile key=&quot;alice&quot;</pre><pre>↓ switch user</pre><pre>Bob</pre><pre>Profile key=&quot;bob&quot;</pre><p>Different key.</p><p>Different identity.</p><p>React remounts the Profile.</p><p>Local state resets.</p><p>This gives us an extremely useful rule:</p><p><strong>Keys don’t just preserve identity. Keys can also intentionally destroy identity.</strong></p><p>That makes key a powerful state-management tool.</p><h3>Want to Reset a Form? Sometimes key Is the Cleanest Answer</h3><p>Imagine:</p><pre>function EditUser({ user }) {<br>  const [name, setName] = useState(user.name)</pre><pre>return (<br>    &lt;input<br>      value={name}<br>      onChange={e =&gt; setName(e.target.value)}<br>    /&gt;<br>  )<br>}</pre><p>You switch from Alice to Bob.</p><p>But the state was initialized only when that component identity mounted.</p><p>So you may discover Bob’s form still contains Alice’s edited value.</p><p>Developers sometimes respond by building increasingly elaborate synchronization effects:</p><pre>useEffect(() =&gt; {<br>  setName(user.name)<br>}, [user])</pre><p>Sometimes that’s appropriate.</p><p>But sometimes the actual business semantics are:</p><p>“When the selected user changes, this should be a completely new form.”</p><p>Then say exactly that to React:</p><pre>&lt;EditUser<br>  key={user.id}<br>  user={user}<br>/&gt;</pre><p>Now a different user means a different component identity.</p><p>The old state is discarded.</p><p>The new component initializes fresh state.</p><p>No synchronization dance required.</p><h3>The Sneakiest Remount Bug: Defining Components Inside Components</h3><p>Now for a bug that can make experienced developers stare at their screen for an uncomfortable amount of time.</p><p>Consider:</p><pre>function App() {<br>  function Input() {<br>    const [value, setValue] = useState(&quot;&quot;)</pre><pre>return (<br>      &lt;input<br>        value={value}<br>        onChange={e =&gt; setValue(e.target.value)}<br>      /&gt;<br>    )<br>  }</pre><pre>return &lt;Input /&gt;<br>}</pre><p>Looks innocent.</p><p>But every time App executes, this happens:</p><pre>function Input() {<br>  // ...<br>}</pre><p>A <strong>new function object</strong> is created.</p><p>Remember what we learned in Part 1:</p><p>For:</p><pre>&lt;Input /&gt;</pre><p>the React element’s type is the actual function reference.</p><p>So render #1:</p><pre>type → Input function #1</pre><p>Render #2:</p><pre>type → Input function #2</pre><p>And:</p><pre>InputFunction1 !== InputFunction2</pre><p>React sees a different type.</p><p>Different type means different component identity.</p><p>Different identity means remount.</p><p>Remount means:</p><pre>state gone<br>effects cleaned up<br>new state initialized<br>new effects mounted</pre><p>So this:</p><pre>function App() {<br>  function Input() {<br>    // ...<br>  }</pre><pre>return &lt;Input /&gt;<br>}</pre><p>can cause surprising state resets.</p><p>Move the component definition outside:</p><pre>function Input() {<br>  const [value, setValue] = useState(&quot;&quot;)</pre><pre>return (<br>    &lt;input<br>      value={value}<br>      onChange={e =&gt; setValue(e.target.value)}<br>    /&gt;<br>  )<br>}</pre><pre>function App() {<br>  return &lt;Input /&gt;<br>}</pre><p>Now the Input function reference is stable.</p><p>This is not just a style preference.</p><p>It’s directly connected to reconciliation.</p><h3>Render Is Not Mount</h3><p>This distinction is essential.</p><p>Developers often say:</p><p>“My component rendered again, so it mounted again.”</p><p>No.</p><p>A component can render hundreds of times while maintaining the same identity.</p><p>Consider:</p><pre>function Counter() {<br>  const [count, setCount] = useState(0)</pre><pre>console.log(&quot;render&quot;)</pre><pre>useEffect(() =&gt; {<br>    console.log(&quot;mounted&quot;)</pre><pre>return () =&gt; {<br>      console.log(&quot;unmounted&quot;)<br>    }<br>  }, [])</pre><pre>return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      {count}<br>    &lt;/button&gt;<br>  )<br>}</pre><p>Click five times.</p><p>You’ll see multiple:</p><pre>render<br>render<br>render<br>render<br>render</pre><p>But under ordinary production behavior, you’re not necessarily seeing:</p><pre>mounted<br>unmounted<br>mounted<br>unmounted<br>mounted</pre><p>The same component identity can render repeatedly.</p><p>Its Fiber persists.</p><p>Its hook state persists.</p><p>Its DOM can persist.</p><p>React is just recalculating what that component wants the UI to look like.</p><p>So:</p><pre>RENDER<br>   ↓<br>&quot;Run the component again&quot;</pre><pre>REMOUNT<br>   ↓<br>&quot;Old identity is gone.<br>Create a new component identity.&quot;</pre><p>Those are radically different events.</p><h3>Reconciliation Is Why State “Lives in React”</h3><p>This leads to a deeper insight.</p><p>Consider:</p><pre>function Counter() {<br>  const [count, setCount] = useState(0)</pre><pre>return &lt;button&gt;{count}&lt;/button&gt;<br>}</pre><p>Where exactly is count stored?</p><p>Not in the Counter function.</p><p>That function finishes executing.</p><p>Its local variables disappear like normal JavaScript locals.</p><p>And the React element doesn’t store your hook state either.</p><p>The element is just a description.</p><p>React associates hook state with the component’s internal Fiber identity.</p><p>Conceptually:</p><pre>React Element<br>{<br>  type: Counter,<br>  props: {}<br>}</pre><pre>↓ reconciled with</pre><pre>Fiber<br>{<br>  type: Counter,<br>  memoizedState: ...<br>  ...<br>}</pre><p>That’s why identity matters so much.</p><p>If React preserves the Fiber identity:</p><pre>state survives</pre><p>If React replaces that identity:</p><pre>state resets</pre><p>Suddenly the rules around keys and types aren’t arbitrary React trivia.</p><p>They’re directly connected to where your state lives.</p><h3>What Actually Happens After setState?</h3><p>Let’s connect everything.</p><p>You click:</p><pre>setCount(count + 1)</pre><p>A common beginner explanation says:</p><p>“React updates the DOM.”</p><p>That’s skipping almost the entire interesting part.</p><p>A better mental model is:</p><pre>setState()<br>    │<br>    ▼<br>React schedules an update<br>    │<br>    ▼<br>Component executes again<br>    │<br>    ▼<br>New React elements are produced<br>    │<br>    ▼<br>React reconciles them against<br>the existing Fiber tree<br>    │<br>    ▼<br>React determines:<br>reuse?<br>update?<br>mount?<br>delete?<br>    │<br>    ▼<br>Render work completes<br>    │<br>    ▼<br>Commit phase<br>    │<br>    ▼<br>Necessary DOM mutations</pre><p>Notice something important.</p><p>The DOM is at the bottom.</p><p>React spends most of this process reasoning about its own structures before touching the browser DOM.</p><h3>Render Phase vs Commit Phase</h3><p>This distinction comes up constantly in senior interviews.</p><p>React broadly separates work into:</p><pre>RENDER PHASE<br>      ↓<br>figure out what should change</pre><pre>COMMIT PHASE<br>      ↓<br>actually apply host changes</pre><p>During the render phase, React can execute components and perform reconciliation.</p><p>Conceptually:</p><pre>old tree<br>   +<br>new element descriptions<br>   ↓<br>reconciliation<br>   ↓<br>work-in-progress tree</pre><p>React is figuring out the next state of the UI.</p><p>Then comes commit.</p><p>That’s where React applies the completed result to the host environment.</p><p>For React DOM, that means things like DOM mutations.</p><p>The key insight:</p><p><strong>Rendering is calculation. Committing is application.</strong></p><p>This is also part of why render functions need to be pure.</p><p>React may perform rendering work without immediately committing it.</p><p>With concurrent rendering, work can even be interrupted or abandoned.</p><p>If your render function performs destructive side effects, React can’t safely treat rendering as speculative work.</p><h3>Why Fiber Matters Here</h3><p>Now Fiber finally has a natural place in the story.</p><p>A Fiber is React’s internal unit of work and bookkeeping structure associated with a component or host node.</p><p>Conceptually, React uses Fiber to keep track of things like:</p><pre>What component is this?</pre><pre>What props does it have?</pre><pre>What state/hooks belong here?</pre><pre>Who is its parent?</pre><pre>Who are its children/siblings?</pre><pre>What work needs to happen?</pre><pre>Does something need committing?</pre><p>React elements are temporary descriptions.</p><p>Fibers represent React’s persistent internal understanding of the rendered tree.</p><p>That’s why:</p><pre>React Element<br>     ↓<br>new description every render</pre><pre>Fiber<br>     ↓<br>persistent internal identity<br>across compatible renders</pre><p>This distinction explains a huge amount of React.</p><h3>Reconciliation Is Really About Reuse</h3><p>When React gets new element descriptions, it doesn’t just ask:</p><p>“What’s different?”</p><p>A more useful way to think about it is:</p><p><strong>“What existing work can I safely reuse?”</strong></p><p>Same compatible identity?</p><p>Reuse.</p><pre>Counter<br>   ↓<br>Counter</pre><pre>reuse existing identity<br>preserve state</pre><p>Different identity?</p><p>Replace.</p><pre>Counter<br>   ↓<br>Input</pre><pre>remove old identity<br>create new identity<br>reset state</pre><p>Stable list key?</p><p>Reuse the correct sibling.</p><pre>User key=42<br>     ↓<br>User key=42</pre><pre>same person</pre><p>Changed key?</p><p>New identity.</p><pre>Profile key=&quot;alice&quot;<br>       ↓<br>Profile key=&quot;bob&quot;</pre><pre>new identity</pre><p>Once you think of reconciliation as an identity-and-reuse algorithm, a lot of React behavior stops being mysterious.</p><h3>A Practical Debugging Checklist</h3><p>The next time state mysteriously resets, don’t immediately blame hooks.</p><p>Ask:</p><pre>Did the component type change?</pre><pre>Did its key change?</pre><pre>Did its position/structure change?</pre><pre>Did I define a component inside another component?</pre><pre>Am I using unstable/random keys?</pre><pre>Am I using array indexes for a list<br>that can reorder, insert, or delete?</pre><pre>Did I intentionally or accidentally<br>cause React to see a new identity?</pre><p>Conversely, if state <strong>isn’t resetting when you expected it to</strong>, ask:</p><pre>Is React preserving the same component<br>because type + position/key still identify<br>it as the same thing?</pre><p>Sometimes:</p><pre>key={somethingMeaningful}</pre><p>is exactly how you tell React:</p><p>“No. This isn’t the same thing anymore.”</p><h3>The Interview Question: “How Does React Preserve State?”</h3><p>This is where you can give a much stronger answer than:</p><p>“React stores state internally.”</p><p>Say:</p><p>React associates state with a component’s position and identity in its internal Fiber tree. Across renders, reconciliation determines whether a new element corresponds to the existing component. When React can preserve that identity, its state is preserved. If the relevant type or key changes such that React treats it as a different component, the old component is unmounted and the new one receives fresh state.</p><p>That’s the answer.</p><p>And now you actually know what it means.</p><h3>The Interview Question: “Why Do Keys Matter?”</h3><p>Don’t say only:</p><p>“They improve list performance.”</p><p>That’s incomplete and can be misleading.</p><p>Say:</p><p>Keys provide stable identity among sibling elements during reconciliation. They allow React to match elements across insertions, deletions and reordering. A stable key helps React preserve the correct component and its state, while an unstable or incorrect key can cause state to be associated with the wrong item or force unnecessary remounts.</p><p>Much stronger.</p><h3>The Interview Question: “Why Shouldn’t I Use the Array Index as a Key?”</h3><p>Say:</p><p>An index represents a position, not necessarily the identity of the underlying data. If items can be inserted, removed or reordered, the same index may refer to a different item on the next render. React can then preserve component state against the wrong item. Stable IDs from the underlying data are usually better keys.</p><p>Notice we’re not saying:</p><p>“Never use indexes.”</p><p>If a static list genuinely never changes ordering, inserts, or deletes, index keys aren’t automatically catastrophic.</p><p>The issue is <strong>identity stability</strong>.</p><p>That’s the principle.</p><h3>The Interview Question: “What’s the Difference Between Re-render and Remount?”</h3><p>Say:</p><p>A re-render means React executes the existing component again to calculate new output while preserving its identity and state. A remount means React discarded the previous component identity and created a new one, so local state is initialized again and mount/unmount lifecycle behavior occurs.</p><p>Short version:</p><pre>RE-RENDER<br>same identity<br>state preserved</pre><pre>REMOUNT<br>new identity<br>state reset</pre><p>That distinction alone will save you hours of debugging.</p><h3>The Interview Question: “What Is Reconciliation?”</h3><p>Here’s the version I’d actually use:</p><p>Reconciliation is React’s process for taking the new element descriptions produced by rendering and matching them against the existing Fiber tree. Based on things such as position, element type and keys, React determines which existing components can be reused, which need updating, and which need to be mounted or removed. Once that work is complete, the commit phase applies the necessary changes to the host environment, such as the DOM.</p><p>That’s senior enough without reciting React’s source code.</p><h3>The One-Paragraph Version for an Interview</h3><p>If someone asks:</p><p>“Explain reconciliation and how React preserves state.”</p><p>Say:</p><p>React components produce new React element descriptions on every render, so React can’t use element object reference equality to determine identity. During reconciliation, React matches those new descriptions against its existing Fiber tree using the structure of the tree, element types and keys. When React determines that an element corresponds to an existing component, it can reuse that Fiber and preserve its state. If the identity changes — for example because the component type or relevant key changes — React replaces that component identity, causing local state to reset. After reconciliation finishes, React enters the commit phase and applies only the necessary host changes, such as DOM mutations.</p><p>That’s the whole story.</p><h3>The Mental Model Worth Keeping</h3><p>Forget “React compares two Virtual DOMs” for a moment.</p><p>Think:</p><pre>NEW RENDER</pre><pre>React Elements<br>               │<br>               ▼<br>        RECONCILIATION<br>               │<br>               │<br>      &quot;Who is still who?&quot;<br>               │<br>       ┌───────┴────────┐<br>       │                │<br>   SAME IDENTITY    NEW IDENTITY<br>       │                │<br>       ▼                ▼<br>     REUSE            REMOUNT<br>       │                │<br>       ▼                ▼<br>preserve state      reset state</pre><pre>│<br>               ▼<br>             COMMIT<br>               │<br>               ▼<br>              DOM</pre><p>React reconciliation isn’t primarily magic object comparison.</p><p>It’s an identity problem.</p><p>React is constantly trying to answer:</p><p>“Is this the same thing I had before?”</p><p>type helps answer it.</p><p>key helps answer it.</p><p>Tree position helps answer it.</p><p>Fiber remembers the result.</p><p>And your component state survives or disappears depending on that answer.</p><p>So the next time an input mysteriously resets, a modal loses its state, or a list item somehow inherits another item’s checkbox:</p><p>Don’t start by blaming useState.</p><p>Ask the more useful question:</p><p><strong>What did I tell React this component’s identity was?</strong></p><p>That’s usually where the body is buried.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1970bb6bbaa0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Component, React Element, ReactNode: They Are Not the Same Thing]]></title>
            <link>https://medium.com/@chris191919torres/react-component-react-element-reactnode-they-are-not-the-same-thing-1cc0495e8cc8?source=rss-aa8b9157038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cc0495e8cc8</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[CristianScript]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 01:48:29 GMT</pubDate>
            <atom:updated>2026-08-11T01:48:29.243Z</atom:updated>
            <content:encoded><![CDATA[<p>You write this every day:</p><pre>function Button() {<br>  return &lt;button&gt;Save&lt;/button&gt;<br>}</pre><p>Simple.</p><p>Then somebody in a React interview asks:</p><blockquote>“What’s the difference between a React component, a React element, and a ReactNode?”</blockquote><p>And suddenly the &lt;button&gt; you’ve been writing for seven years starts looking suspicious.</p><p>Is Button the component?</p><p>Is &lt;Button /&gt; the component?</p><p>Is &lt;button&gt; a DOM element?</p><p>Is JSX the Virtual DOM?</p><p>Where does ReactNode fit?</p><p>And why, if you inspect a React element deeply enough, does some mysterious property called $$typeof appear?</p><p>The problem isn’t that these concepts are particularly difficult. The problem is that we casually use words like <em>component</em>, <em>element</em>, <em>node</em>, <em>Virtual DOM</em>, and <em>render</em> as if they all mean roughly the same thing.</p><p>They don’t.</p><p>So let’s tear apart one tiny React component and follow it all the way from JavaScript function to actual pixels on your screen.</p><h3>Start With the Simplest Distinction</h3><p>Consider:</p><pre>function Button() {<br>  return &lt;button&gt;Save&lt;/button&gt;<br>}</pre><p>There are already several different things happening here.</p><p>First:</p><pre>Button</pre><p>That’s a <strong>React component</strong>.</p><p>More precisely, it’s a JavaScript function that React can use as a component.</p><p>Then:</p><pre>&lt;Button /&gt;</pre><p>That’s JSX describing an instance of that component.</p><p>That JSX produces a <strong>React element</strong>.</p><p>And then:</p><pre>&lt;button&gt;Save&lt;/button&gt;</pre><p>also produces a React element.</p><p>Eventually React DOM uses that description to create or update an actual browser DOM node:</p><pre>&lt;button&gt;Save&lt;/button&gt;</pre><p>So already we have:</p><pre>Button<br>   ↓<br>Component function<br></pre><pre>&lt;Button /&gt;<br>   ↓<br>React Element<br></pre><pre>&lt;button /&gt;<br>   ↓<br>React Element<br></pre><pre>HTMLButtonElement<br>   ↓<br>Actual DOM node</pre><p>These are four different things.</p><p>And confusing them is where most explanations go sideways.</p><h3>A React Component Is Just a Function</h3><p>Let’s remove React from our brain for a second.</p><p>This:</p><pre>function Button() {<br>  return &lt;button&gt;Save&lt;/button&gt;<br>}</pre><p>is fundamentally a JavaScript function.</p><p>React gives that function special meaning because we’re using it as a component.</p><p>You can even prove that:</p><pre>console.log(typeof Button)</pre><p>You’ll get:</p><pre>function</pre><p>Nothing magical happened.</p><p>There’s no secret ReactComponent object floating around.</p><p>The component is simply:</p><pre>Button</pre><p>the function itself.</p><p>But this:</p><pre>&lt;Button /&gt;</pre><p>is <strong>not the function</strong>.</p><p>That’s where things get interesting.</p><h3>&lt;Button /&gt;</h3><h3>Becomes an Object</h3><p>When you write:</p><pre>const element = &lt;Button /&gt;</pre><p>JSX eventually produces a JavaScript object representing that UI.</p><p>Conceptually, it resembles:</p><pre>{<br>  $$typeof: Symbol(...),<br>  type: Button,<br>  key: null,<br>  props: {}<br>}</pre><p>That’s a <strong>React element</strong>.</p><p>And this distinction is worth burning into your brain:</p><pre>Button<br>   ↓<br>FUNCTION<br></pre><pre>&lt;Button /&gt;<br>   ↓<br>OBJECT</pre><p>The component is the recipe.</p><p>The element is the order ticket saying:</p><p>“React, I would like one Button, please.”</p><p>React hasn’t necessarily created any DOM yet.</p><p>It’s holding a description.</p><h3>React Elements Are Descriptions, Not DOM Nodes</h3><p>Consider:</p><pre>const element = (<br>  &lt;button className=&quot;primary&quot;&gt;<br>    Save<br>  &lt;/button&gt;<br>)</pre><p>A beginner might mentally imagine React immediately creating:</p><pre>&lt;button class=&quot;primary&quot;&gt;<br>  Save<br>&lt;/button&gt;</pre><p>But that’s skipping several steps.</p><p>What React receives first is conceptually closer to:</p><pre>{<br>  $$typeof: Symbol(...),<br>  type: &quot;button&quot;,<br>  key: null,<br>  props: {<br>    className: &quot;primary&quot;,<br>    children: &quot;Save&quot;<br>  }<br>}</pre><p>That’s just data.</p><p>A JavaScript object.</p><p>It says:</p><p>“I want a button. Give it the class primary. Put Save inside it.”</p><p>The element describes what should exist.</p><p>React DOM later deals with making that description reality.</p><p>So:</p><pre>React Element<br>      ≠<br>DOM Element</pre><p>A React element is a description.</p><p>A DOM element is an actual browser object.</p><h3>The</h3><h3>type</h3><h3>Property Is More Interesting Than It Looks</h3><p>Consider:</p><pre>&lt;div&gt;Hello&lt;/div&gt;</pre><p>Its React element conceptually has:</p><pre>{<br>  type: &quot;div&quot;<br>}</pre><p>Why a string?</p><p>Because &quot;div&quot; tells React:</p><p>“This is a host element.”</p><p>In React DOM, that ultimately corresponds to a browser DOM element.</p><p>Same thing with:</p><pre>&lt;button /&gt;</pre><p>Conceptually:</p><pre>{<br>  type: &quot;button&quot;<br>}</pre><p>But now try:</p><pre>function Button() {<br>  return &lt;button&gt;Save&lt;/button&gt;<br>}</pre><pre>const element = &lt;Button /&gt;</pre><p>Now the type isn’t &quot;Button&quot;.</p><p>It’s:</p><pre>{<br>  type: Button<br>}</pre><p>The actual function reference.</p><p>That’s a major distinction.</p><pre>&lt;div /&gt;<br>   ↓<br>type: &quot;div&quot;<br></pre><pre>&lt;Button /&gt;<br>   ↓<br>type: Button<br>      ↑<br>actual JavaScript function</pre><p>So when React encounters an element whose type is a function, it knows it needs to render that component.</p><p>Conceptually:</p><pre>Button()</pre><p>returns:</p><pre>&lt;button&gt;Save&lt;/button&gt;</pre><p>which produces another React element whose type is:</p><pre>&quot;button&quot;</pre><p>So our little component travels through React something like this:</p><pre>&lt;Button /&gt;<br>    ↓</pre><pre>{<br>  type: Button,<br>  props: {}<br>}</pre><pre>    ↓</pre><pre>React renders Button</pre><pre>    ↓</pre><pre>&lt;button&gt;Save&lt;/button&gt;</pre><pre>    ↓</pre><pre>{<br>  type: &quot;button&quot;,<br>  props: {<br>    children: &quot;Save&quot;<br>  }<br>}</pre><pre>    ↓</pre><pre>React DOM</pre><pre>    ↓</pre><pre>Actual browser button</pre><p>Once you see this pipeline, React starts feeling much less magical.</p><p>It’s descriptions producing descriptions until React eventually reaches something the host renderer knows how to create.</p><h3>Okay, Then What Is</h3><h3>$$typeof</h3><h3>?</h3><p>This property looks like something you absolutely should not touch:</p><pre>$$typeof</pre><p>That’s because you probably shouldn’t.</p><p>React elements contain internal metadata allowing React to identify what kind of React object it’s dealing with.</p><p>Conceptually:</p><pre>{<br>  $$typeof: Symbol(...),<br>  type: Button,<br>  key: null,<br>  props: {}<br>}</pre><p>Think of $$typeof as React saying:</p><p>“Yes, this object belongs to me.”</p><p>It’s not the same as type.</p><p>That’s important.</p><pre>$$typeof<br>   ↓<br>What kind of React object is this?<br></pre><pre>type<br>   ↓<br>What does this element represent?</pre><p>For:</p><pre>&lt;Button /&gt;</pre><p>the type is approximately:</p><pre>Button</pre><p>For:</p><pre>&lt;div /&gt;</pre><p>the type is:</p><pre>&quot;div&quot;</pre><p>$$typeof, meanwhile, is React’s internal marker.</p><p>Don’t build application logic around its exact value. It’s an implementation detail and React internals can change.</p><p>Knowing <em>why it exists</em> is useful.</p><p>Depending on its exact representation is not.</p><h3>Now ReactNode Enters the Chat and Ruins Everyone’s Vocabulary</h3><p>You’ve probably written this:</p><pre>type Props = {<br>  children: React.ReactNode<br>}</pre><p>So what’s a ReactNode?</p><p>The easiest answer is:</p><p>ReactNode describes the broader universe of values React knows how to render.</p><p>For example:</p><pre>const a: ReactNode = &lt;Button /&gt;<br>const b: ReactNode = &quot;Hello&quot;<br>const c: ReactNode = 42<br>const d: ReactNode = null<br>const e: ReactNode = undefined</pre><p>A React element is therefore one kind of ReactNode.</p><p>But a ReactNode doesn’t have to be an element.</p><p>For example:</p><pre>const message: ReactNode = &quot;Hello&quot;</pre><p>Perfectly valid.</p><p>But:</p><pre>const message: ReactElement = &quot;Hello&quot;</pre><p>Nope.</p><p>A string is renderable, but it isn’t a React element object.</p><p>Picture it like this:</p><pre>ReactNode<br>                      │<br>       ┌──────────────┼──────────────┐<br>       │              │              │<br> ReactElement       string         number<br>       │<br>   ┌───┴────┐<br>   │        │<br> &lt;div /&gt; &lt;Button /&gt;</pre><pre>       plus things like<br>       null, undefined,<br>       collections, etc.</pre><p>This gives us our first interview-quality sentence:</p><p>A React element is a ReactNode, but not every ReactNode is a React element.</p><p>That’s the distinction.</p><h3>So What Does JSX Actually Do?</h3><p>Here’s another sentence developers repeat:</p><p>“JSX gets converted into React.createElement().”</p><p>Historically, yes.</p><p>But if you’re using modern React tooling, that’s no longer the full story.</p><p>The classic JSX transform would take:</p><pre>&lt;Button name=&quot;Cristian&quot; /&gt;</pre><p>and turn it into something roughly like:</p><pre>React.createElement(<br>  Button,<br>  { name: &quot;Cristian&quot; }<br>)</pre><p>That call would produce the React element.</p><p>This is also why old React projects had this everywhere:</p><pre>import React from &quot;react&quot;</pre><p>Even if the file never explicitly used the React variable.</p><p>JSX needed it.</p><p>Modern React tooling normally uses the <strong>automatic JSX runtime</strong>.</p><p>Instead of compiling every JSX expression directly into:</p><pre>React.createElement(...)</pre><p>the compiler can use functions from:</p><pre>react/jsx-runtime</pre><p>Conceptually something like:</p><pre>jsx(Button, {<br>  name: &quot;Cristian&quot;<br>})</pre><p>The important thing isn’t memorizing jsx versus jsxs.</p><p>The important thing is understanding:</p><pre>JSX<br>   ↓<br>Compiler<br>   ↓<br>React JSX runtime<br>   ↓<br>React Element</pre><p>JSX is syntax.</p><p>React elements are objects.</p><p>Those are not the same thing.</p><p>And yes, React.createElement() still exists.</p><p>Modern JSX just doesn’t necessarily compile directly to it anymore.</p><h3>Wait — Is the React Element the Virtual DOM?</h3><p>Here’s where terminology gets messy.</p><p>People often teach React like this:</p><pre>JSX<br> ↓<br>Virtual DOM<br> ↓<br>Real DOM</pre><p>That’s useful when you’re learning React on day one.</p><p>It’s not particularly precise once you start digging into React internals.</p><p>A better picture is:</p><pre>JSX<br> ↓<br>React Elements<br> ↓<br>React reconciliation / Fiber<br> ↓<br>Commit<br> ↓<br>Real DOM</pre><p>React elements describe the UI React wants.</p><p>Fiber is part of React’s internal machinery for tracking the tree and performing rendering work.</p><p>The DOM is what actually exists in the browser.</p><p>So don’t think:</p><pre>React Element = Fiber = DOM Node</pre><p>Absolutely not.</p><p>They’re different layers.</p><p>A useful mental model is:</p><pre>React Element<br>     ↓<br>&quot;What UI do you want?&quot;<br></pre><pre>Fiber<br>     ↓<br>&quot;What currently exists,<br>what state belongs here,<br>and what work needs doing?&quot;<br></pre><pre>DOM<br>     ↓<br>&quot;What actually exists<br>in the browser?&quot;</pre><p>That’s much closer to reality.</p><h3>Now Reconciliation Finally Makes Sense</h3><p>Suppose our component renders:</p><pre>function Counter() {<br>  const [count, setCount] = useState(0)</pre><pre>  return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      {count}<br>    &lt;/button&gt;<br>  )<br>}</pre><p>Initially React gets an element description conceptually like:</p><pre>{<br>  type: &quot;button&quot;,<br>  props: {<br>    children: 0<br>  }<br>}</pre><p>Then you click.</p><pre>setCount(1)</pre><p>React schedules an update and renders the component again.</p><p>Now React gets a new description:</p><pre>{<br>  type: &quot;button&quot;,<br>  props: {<br>    children: 1<br>  }<br>}</pre><p>React doesn’t need to destroy the entire webpage and recreate everything.</p><p>It can reason about the old and new result:</p><pre>OLD</pre><pre>&lt;button&gt;<br>  0<br>&lt;/button&gt;<br></pre><pre>NEW</pre><pre>&lt;button&gt;<br>  1<br>&lt;/button&gt;</pre><p>Same button.</p><p>Different text.</p><p>So eventually the necessary host mutation is basically:</p><pre>0 → 1</pre><p>Determining how the new render relates to the existing rendered tree is the job of <strong>reconciliation</strong>.</p><p>This also explains something developers get wrong all the time:</p><p>A React render does not necessarily mean a DOM update.</p><p>Your component can execute again.</p><p>React can produce new element objects.</p><p>React can reconcile them.</p><p>And then determine:</p><p>“Nothing relevant in the DOM actually needs changing.”</p><p>Rendering and DOM mutation are different stages.</p><h3>type</h3><h3>and</h3><h3>key</h3><h3>Suddenly Become Very Important</h3><p>Imagine one render produces:</p><pre>&lt;Button /&gt;</pre><p>and the next produces:</p><pre>&lt;Button /&gt;</pre><p>React sees the same component type in the corresponding position.</p><p>That gives React a basis for preserving that component’s identity.</p><p>But suppose:</p><pre>&lt;Button /&gt;</pre><p>becomes:</p><pre>&lt;Input /&gt;</pre><p>Now the types are different:</p><pre>Button → Input</pre><p>React treats that as a different component identity and generally remounts that part of the tree.</p><p>Keys matter particularly among siblings:</p><pre>users.map(user =&gt; (<br>  &lt;User<br>    key={user.id}<br>    user={user}<br>  /&gt;<br>))</pre><p>You can think of them like:</p><pre>type<br> ↓<br>&quot;What kind of thing is this?&quot;<br></pre><pre>key<br> ↓<br>&quot;Which one is this among its siblings?&quot;</pre><p>This is why random keys are such a terrible idea.</p><p>If you do:</p><pre>&lt;User key={Math.random()} /&gt;</pre><p>you’re effectively handing React a new identity every render and then wondering why state keeps disappearing.</p><p>React isn’t confused.</p><p>You lied to it.</p><h3>The Whole Pipeline</h3><p>Now we can finally connect everything without needing a React dictionary open in another tab.</p><p>Suppose:</p><pre>function App() {<br>  return &lt;Button label=&quot;Save&quot; /&gt;<br>}</pre><p>Start at the top.</p><p>App and Button are:</p><pre>COMPONENTS</pre><p>React renders App.</p><p>It encounters:</p><pre>&lt;Button label=&quot;Save&quot; /&gt;</pre><p>JSX produces a:</p><pre>REACT ELEMENT</pre><p>conceptually:</p><pre>{<br>  type: Button,<br>  props: {<br>    label: &quot;Save&quot;<br>  }<br>}</pre><p>React sees that type is the Button function.</p><p>So it renders Button.</p><p>Button returns:</p><pre>&lt;button&gt;Save&lt;/button&gt;</pre><p>which produces another:</p><pre>REACT ELEMENT</pre><p>conceptually:</p><pre>{<br>  type: &quot;button&quot;,<br>  props: {<br>    children: &quot;Save&quot;<br>  }<br>}</pre><p>React performs its rendering and reconciliation work through its Fiber architecture.</p><p>Eventually React reaches the commit phase.</p><p>React DOM applies the necessary host mutations.</p><p>And finally the browser has:</p><pre>&lt;button&gt;Save&lt;/button&gt;</pre><p>So the complete mental picture is:</p><pre>COMPONENT</pre><pre>               Button<br>                 │<br>                 ▼</pre><pre>                 JSX</pre><pre>              &lt;Button /&gt;<br>                 │<br>                 ▼</pre><pre>            JSX RUNTIME<br>                 │<br>                 ▼</pre><pre>           REACT ELEMENT</pre><pre>        {<br>          type: Button,<br>          props: {}<br>        }</pre><pre>                 │<br>                 ▼</pre><pre>          React renders Button</pre><pre>                 │<br>                 ▼</pre><pre>          &lt;button&gt;Save&lt;/button&gt;</pre><pre>                 │<br>                 ▼</pre><pre>         another React Element</pre><pre>        {<br>          type: &quot;button&quot;,<br>          props: {<br>            children: &quot;Save&quot;<br>          }<br>        }</pre><pre>                 │<br>                 ▼</pre><pre>       RECONCILIATION / FIBER</pre><pre>                 │<br>                 ▼</pre><pre>              COMMIT</pre><pre>                 │<br>                 ▼</pre><pre>             REAL DOM</pre><pre>        &lt;button&gt;Save&lt;/button&gt;</pre><p>That’s React without the magic.</p><p>It’s functions producing descriptions, React reasoning about those descriptions, and a renderer eventually synchronizing the host environment with the result.</p><h3>The Interview Trap: “Is</h3><h3>&lt;Button /&gt;</h3><h3>the Component?”</h3><p>This is where I’d be precise.</p><p>If an interviewer asks:</p><p>“Is &lt;Button /&gt; a React component?”</p><p>I’d say:</p><p>“We commonly refer to it casually as a component in everyday conversation, but technically Button is the component function, while &lt;Button /&gt; is JSX that produces a React element whose type points to Button.”</p><p>That’s the kind of distinction interviewers like because you’re not just repeating vocabulary.</p><p>You understand what actually exists at runtime.</p><pre>Button<br>   ↓<br>Component function<br></pre><pre>&lt;Button /&gt;<br>   ↓<br>JSX<br></pre><pre>result<br>   ↓<br>React Element<br></pre><pre>element.type<br>   ↓<br>Button function</pre><h3>The Interview Trap: “Does Rendering Mean React Updated the DOM?”</h3><p>No.</p><p>And this one is worth answering confidently.</p><p>A state update might cause:</p><pre>State update<br>    ↓<br>React schedules work<br>    ↓<br>Component renders<br>    ↓<br>New React elements<br>    ↓<br>Reconciliation<br>    ↓<br>React determines what changed<br>    ↓<br>Commit phase<br>    ↓<br>Necessary DOM mutations</pre><p>The component rendering again doesn’t guarantee a DOM mutation.</p><p>React may discover that the host output is effectively unchanged.</p><p>That’s why saying:</p><p>“React re-rendered the DOM”</p><p>is usually sloppy terminology.</p><p>React re-renders components.</p><p>Then it determines whether the DOM needs changing.</p><h3>The One-Paragraph Version for an Interview</h3><p>If somebody asks:</p><p>“What’s the difference between ReactNode, ReactElement and a React Component?”</p><p>Say this:</p><p>A React component is typically a function that defines reusable UI. When React renders that component, it produces React-renderable output, commonly React elements. A React element is a lightweight JavaScript object describing what React should render, containing information such as type, key, and props, plus internal metadata such as $$typeof. ReactNode is broader: it’s the TypeScript type representing values React can render, including React elements, strings, numbers, null and collections. So a React element is a ReactNode, but not every ReactNode is a React element.</p><p>If they ask:</p><p>“Does JSX compile to React.createElement?”</p><p>Continue:</p><p>Historically, the classic JSX transform did exactly that. Modern React tooling normally uses the automatic JSX runtime instead, which produces the same fundamental thing: React elements.</p><p>And if they push into internals:</p><p>React uses those element descriptions during rendering and reconciliation against its existing Fiber tree. Fiber is React’s internal work and bookkeeping structure. Once React determines the necessary host changes, React DOM applies them during the commit phase.</p><p>Then stop.</p><p>Don’t answer a five-minute Fiber question when they asked what ReactNode means.</p><p>Knowing where to stop is also part of knowing the subject.</p><h3>The Mental Model Worth Keeping</h3><p>If all of this disappears from your brain five minutes before an interview, remember four lines:</p><pre>Component = the function</pre><pre>Element   = the object description</pre><pre>Node      = anything React can render</pre><pre>DOM Node  = the actual browser object</pre><p>And if they go deeper:</p><pre>JSX<br> ↓<br>React Element<br> ↓<br>React rendering + reconciliation<br> ↓<br>Fiber tracks the work<br> ↓<br>Commit<br> ↓<br>DOM</pre><p>That’s it.</p><p>&lt;Button /&gt; isn’t a magical mini-DOM node.</p><p>Button isn’t an object React stores somewhere because you called it a component.</p><p>ReactNode isn’t another kind of Virtual DOM.</p><p>And JSX isn’t HTML secretly living inside JavaScript.</p><p>At the bottom of the whole thing are surprisingly ordinary ingredients: functions, objects, references, and a renderer trying to keep reality synchronized with the description you just gave it.</p><p>React gets significantly easier once you stop imagining magic between the angle brackets.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cc0495e8cc8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React 19: The Update That Finally Let You Delete Code]]></title>
            <link>https://medium.com/@chris191919torres/react-19-the-update-that-finally-let-you-delete-code-c56b8790c05d?source=rss-aa8b9157038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c56b8790c05d</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[CristianScript]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 04:45:57 GMT</pubDate>
            <atom:updated>2026-08-07T04:45:57.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTVBn2ZmJqQZB96rBZInVg.png" /></figure><p>Every few years React ships something that makes you rewrite a chunk of your app. React 19 is a little different. React 19 mostly lets you delete things.</p><p>Delete your useMemo calls. Delete your useCallback wrappers. Delete that thirty line form handler with its own loading boolean and its own error boolean and its own “did it actually submit” boolean. React 19 looked at a decade of boilerplate patterns and said, quietly, we can just do this for you now.</p><p>Let us go through what actually shipped, why it matters, and enough code to make it real.</p><blockquote>The React Compiler: Memoization Becomes Someone Else’s Problem</blockquote><p>For years, writing performant React meant becoming fluent in a very specific kind of paranoia. Every function passed as a prop, wrap it in <strong>useCallback</strong>, just in case. Every computed value, wrap it in useMemo, just in case. Forget one dependency in the array and enjoy a bug that only shows up in production at 2am.</p><p>The React Compiler, which reached stable 1.0 alongside React 19, does this analysis for you at build time. It looks at your component, figures out what actually depends on what, and inserts the equivalent memoization automatically. You stop writing it by hand.</p><p>Before, the way basically everyone wrote React for the last five years:</p><pre>function ProductList(props) {<br>  const products = props.products<br>  const category = props.category<br><br>  const filtered = useMemo(function () {<br>    return products.filter(function (p) {<br>      return p.category === category<br>    })<br>  }, [products, category])<br><br>  const handleClick = useCallback(function (id) {<br>    console.log(&#39;clicked&#39;, id)<br>  }, [])<br><br>  return filtered.map(function (p) {<br>    return React.createElement(<br>      &#39;div&#39;,<br>      {<br>        key: p.id,<br>        onClick: function () {<br>          handleClick(p.id)<br>        }<br>      },<br>      p.name<br>    )<br>  })<br>}</pre><p>After, with the compiler doing the memoization for you:</p><pre>function ProductList(props) {<br>  const filtered = props.products.filter(function (p) {<br>    return p.category === props.category<br>  })<br><br>  function handleClick(id) {<br>    console.log(&#39;clicked&#39;, id)<br>  }<br><br>  return filtered.map(function (p) {<br>    return React.createElement(<br>      &#39;div&#39;,<br>      {<br>        key: p.id,<br>        onClick: function () {<br>          handleClick(p.id)<br>        }<br>      },<br>      p.name<br>    )<br>  })<br>}</pre><p>Same performance characteristics. Half the code. No dependency array to get wrong at 2am. The compiler is doing static analysis on your data flow and deciding what needs to be cached between renders, which is exactly the kind of tedious, error prone bookkeeping a computer should be doing instead of a human.</p><p>Worth saying plainly: this does not mean <strong>useMemo</strong> and <strong>useCallback</strong> are banned or deprecated. They still work. You will still see them in codebases for a long time, including in libraries you depend on that have not migrated yet. The compiler just means you personally do not need to reach for them by default anymore in new code.</p><h4>Actions: Forms Stop Being a Chore</h4><p>Before React 19, submitting a form and handling the result meant wiring up your own pending state, your own error state, and your own success state, every single time, in every single form, forever.</p><p>The old way, which if you have shipped any real app you have written some version of a hundred times:</p><pre>function OldForm() {<br>  const [name, setName] = useState(&#39;&#39;)<br>  const [isPending, setIsPending] = useState(false)<br>  const [error, setError] = useState(null)<br><br>  function handleSubmit(e) {<br>    e.preventDefault()<br>    setIsPending(true)<br>    setError(null)<br><br>    updateName(name)<br>      .then(function () {<br>        setIsPending(false)<br>      })<br>      .catch(function (err) {<br>        setError(err)<br>        setIsPending(false)<br>      })<br>  }<br><br>  return React.createElement(<br>    &#39;form&#39;,<br>    { onSubmit: handleSubmit },<br>    React.createElement(&#39;input&#39;, {<br>      value: name,<br>      onChange: function (e) {<br>        setName(e.target.value)<br>      }<br>    }),<br>    React.createElement(<br>      &#39;button&#39;,<br>      { disabled: isPending },<br>      &#39;Update&#39;<br>    ),<br>    error<br>      ? React.createElement(&#39;p&#39;, null, error.message)<br>      : null<br>  )<br>}</pre><p>React 19 introduces <strong>Actions</strong> and a <strong>hook</strong> built on top of them called <strong>useActionState</strong>, which folds all three of those states into one hook call.</p><pre>function NewForm() {<br>  const [error, submitAction, isPending] = useActionState(<br>    async function (previousState, formData) {<br>      const name = formData.get(&#39;name&#39;)<br><br>      try {<br>        await updateName(name)<br>        return null<br>      } catch (err) {<br>        return err.message<br>      }<br>    },<br>    null<br>  )<br><br>  return React.createElement(<br>    &#39;form&#39;,<br>    { action: submitAction },<br>    React.createElement(&#39;input&#39;, {<br>      name: &#39;name&#39;<br>    }),<br>    React.createElement(<br>      &#39;button&#39;,<br>      { disabled: isPending },<br>      &#39;Update&#39;<br>    ),<br>    error<br>      ? React.createElement(&#39;p&#39;, null, error)<br>      : null<br>  )<br>}</pre><p>Notice the form tag now takes an action prop directly, the way plain HTML forms always could, except now that action can be an async function instead of a URL. React tracks pending and error state for you and hands them back as part of the same hook call. No more three separate useState calls doing the emotional labor your form should be doing itself.</p><h4>useOptimistic: Lying To The User, Politely</h4><p>Here is a genuinely nice one. Sometimes you want the UI to update instantly, before the server has actually confirmed anything, because waiting for a round trip makes even a fast backend feel sluggish. Think liking a post, or checking off a to do item.</p><p><strong>useOptimistic</strong> lets you show the new state immediately, then quietly reconcile it once the real response comes back.</p><pre>function TodoItem(props) {<br>  const [optimisticDone, setOptimisticDone] = useOptimistic(<br>    props.todo.done,<br>    function (currentState, newValue) {<br>      return newValue<br>    }<br>  )<br><br>  async function toggle() {<br>    setOptimisticDone(!optimisticDone)<br>    await updateTodoOnServer(<br>      props.todo.id,<br>      !optimisticDone<br>    )<br>  }<br><br>  return React.createElement(<br>    &#39;label&#39;,<br>    null,<br>    React.createElement(&#39;input&#39;, {<br>      type: &#39;checkbox&#39;,<br>      checked: optimisticDone,<br>      onChange: toggle<br>    }),<br>    props.todo.text<br>  )<br>}</pre><p>The checkbox flips the instant you click it. If the server call fails, React quietly reverts the optimistic value back to the real one. Your user gets a snappy interface, your data stays correct, and you did not have to hand write any of the rollback logic yourself.</p><h4>The use API: Reading Promises Mid Render, On Purpose</h4><p>React 19 introduced a new function called use, which lets you read the value of a promise or a context directly during render. The unusual part, and the part worth pausing on, is that unlike every hook before it, use can be called conditionally. Inside an if statement. Inside a loop. It breaks the old rules of hooks on purpose, because it is not technically a hook, it is a different kind of primitive entirely.</p><pre>function Comments(props) {<br>  if (!props.commentsPromise) {<br>    return null<br>  }<br><br>  const comments = use(props.commentsPromise)<br><br>  return comments.map(function (c) {<br>    return React.createElement(<br>      &#39;p&#39;,<br>      { key: c.id },<br>      c.text<br>    )<br>  })<br>}</pre><p>When use encounters a promise that has not resolved yet, the component suspends, and whatever Suspense boundary is wrapping it shows its fallback until the data arrives. This plays directly into Server Components, letting you kick off data fetching on the server and read the result on the client without a waterfall of separate loading states.</p><p><strong>ref As A Normal Prop</strong></p><p>This one is small but it removes a genuinely annoying piece of ceremony. In React 18 and earlier, if you wanted a component to accept a ref, you had to wrap the whole thing in <strong>forwardRef</strong>.</p><p>Old way:</p><pre>const Input = React.forwardRef(function (props, ref) {<br>  return React.createElement(&#39;input&#39;, {<br>    ref: ref,<br>    className: props.className<br>  })<br>})</pre><p>New way, in React 19:</p><pre>function Input(props) {<br>  return React.createElement(&#39;input&#39;, {<br>    ref: props.ref,<br>    className: props.className<br>  })<br>}</pre><p>ref is just a prop now, like any other prop. forwardRef still works for backward compatibility, but you do not need it for new components, and one less wrapper function around every reusable input component is one less thing to explain to a junior developer.</p><h4><strong>Document Metadata, Handled Natively</strong></h4><p>Rendering a title tag or a meta tag from deep inside a component tree used to mean reaching for a separate library like react helmet. React 19 handles this natively. Render a title or meta tag anywhere in your component tree, even nested three components deep, and React hoists it into the document head automatically.</p><pre>function BlogPost(props) {<br>  return React.createElement(<br>    React.Fragment,<br>    null,<br>    React.createElement(<br>      &#39;title&#39;,<br>      null,<br>      props.post.title<br>    ),<br>    React.createElement(&#39;meta&#39;, {<br>      name: &#39;description&#39;,<br>      content: props.post.summary<br>    }),<br>    React.createElement(<br>      &#39;article&#39;,<br>      null,<br>      props.post.body<br>    )<br>  )<br>}</pre><p>No portal, no external library, no manual head manipulation. It just works, because React itself now understands that these tags belong in the head regardless of where in the tree they were written.</p><h4><strong>Server Components And Server Functions Are Stable</strong></h4><p>This is less a single feature and more a shift in how you think about where your code runs at all. Server Components render ahead of time, either at build time or per request, and never ship their JavaScript to the browser at all. Server Functions, marked with a use server directive, are plain functions that live on the server but can be called directly from client code, no manually built API route required.</p><pre>async function updateName(formData) {<br>  &#39;use server&#39;<br><br>  const name = formData.get(&#39;name&#39;)<br><br>  await db.users.update({<br>    name: name<br>  })<br>}</pre><p>That function never runs in the browser. React handles the network call for you behind the scenes when a client component invokes it. The mental model React is pushing you toward in 2026 is less a JavaScript library that happens to run in a browser tab, and more a single component model that spans both the server and the client, with React deciding which parts of the tree belong where.</p><h4>The Honest Summary</h4><p>The compiler removes the memoization busywork. Actions and useActionState remove the form boilerplate busywork. useOptimistic removes the rollback busywork. use lets you read promises and context without contorting your component structure around them. ref as a prop and native document metadata remove two small but constant annoyances. Server Components and Server Functions blur the line between backend and frontend code until the line mostly stops mattering.</p><p>None of these individually feel like a revolution. Together, they add up to something close to one: a version of React where a meaningful fraction of the code you used to write by hand simply is not necessary anymore. Which, if you have ever debugged a stale closure inside a useCallback at midnight, is a genuinely wonderful thing to hear.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c56b8790c05d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Fiber: The Linked List That Saved Your Typing]]></title>
            <link>https://medium.com/@chris191919torres/react-fiber-the-linked-list-that-saved-your-typing-25176dcf94a8?source=rss-aa8b9157038e------2</link>
            <guid isPermaLink="false">https://medium.com/p/25176dcf94a8</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[CristianScript]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 04:06:55 GMT</pubDate>
            <atom:updated>2026-08-07T04:06:55.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWXZXQG7e31-0w9KiFICqw.png" /></figure><p>Picture this: you’re filling out a form, typing away, feeling productive. Somewhere in the background, a giant list of 10,000 rows is trying to re-render. And your keystrokes just… stop showing up. The cursor blinks. Nothing happens. You start questioning your life choices, your keyboard, possibly your career.</p><p>That’s not a bug. That’s just what React looked like before 2017.</p><p>This is the story of how React fixed that — not with a clever trick, not with more servers, not with “just add a loading spinner,” but with a full rewrite of its core engine built around one deceptively boring data structure: <strong>the linked list.</strong></p><p>Yes. The thing from your CS101 course. The one you swore you’d never use again after the final exam. It’s quietly running every React app you’ve ever used.</p><p><strong>The Problem: React Used to Be a Bulldozer</strong></p><p>Before React 16, the reconciler — the part of React that figures out what changed and updates the DOM — worked using plain old JavaScript recursion. A component would render, call itself for each child, which called itself for each of <em>its</em> children, and so on, all the way down.</p><p>This sounds fine until you remember one very inconvenient fact about JavaScript: <strong>it’s single-threaded</strong>, and a recursive call stack <strong>cannot be paused.</strong> Once you start unwinding a deep recursive tree, you’re locked in. You can’t just… stop halfway and go check if the user pressed a key. The browser has to wait its turn, like a customer stuck behind someone arguing with a cashier about an expired coupon.</p><p>So if your component tree was big — and in real apps, it always eventually is — React would just plow through the entire thing, blocking the main thread the whole time. Typing, scrolling, clicking: all frozen until React finished its self-imposed homework assignment.</p><blockquote>React needed a way to say: hold on, let me pause this and go handle something more important first. But you can’t pause a call stack. So the React team asked a better question:</blockquote><h4><strong>What if we didn’t use the call stack at all?</strong></h4><p>Fiber is best understood not as a new *feature*, but as a new *representation* — React describes your UI as a tree, but instead of using nested function calls to walk it, it builds an actual, explicit, JavaScript-object linked list.</p><p>Here’s the wild part: a fiber is just… an object. No magic, no special runtime, no secret sauce baked into V8. Just this:</p><pre>{<br> type: &#39;div&#39;,<br> key: null,<br> pendingProps: { className: &#39;card&#39; },<br> memoizedState: null,<br> child: null,<br> sibling: null,<br> return: null,<br> alternate: null,<br> flags: 0,<br>}</pre><p>One of these gets created for *every* component and DOM node in your app. And the three fields doing all the heavy lifting are `child`, `sibling`, and `return`. That’s it. That’s the whole “linked list” part of the plot twist.</p><p>- `child` → my first child fiber<br>- `sibling` → the next fiber at my same level<br>- `return` → my parent fiber</p><p>No arrays. No `children[0]`, `children[1]`, `children[2]`. Just pointers, daisy-chained together like a conga line where everyone’s holding hands with exactly one person in front and one person to the side.</p><p><strong>Why a Linked List, Though? Why Not Just… Keep the Recursion?</strong></p><p>This is the part most explanations skip, and it’s the part that actually matters.</p><p>A linked list can be walked with a <strong>loop</strong>, not recursion. And loops have a superpower recursion doesn’t: <strong>you can stop them whenever you want and remember exactly where you were.</strong></p><p>Here’s what React’s real work loop looks like, logically:</p><pre>if (fiber.child) {<br> go to fiber.child<br>} else if (fiber.sibling) {<br> go to fiber.sibling<br>} else {<br> go to fiber.return, then try ITS sibling<br>}</pre><p>Notice something? At any given moment, React’s <em>entire</em> sense of “where am I in this tree” is one single variable — the current fiber. One pointer. That’s the whole state.</p><p>Compare that to a recursive call stack, where “where am I” is smeared across dozens of stacked function calls, each with its own local variables, none of which you can just… set aside and come back to later. A JS call stack is like a conversation where everyone has to finish their sentence before anyone else can talk. A linked-list loop is like a group chat — you can leave mid-conversation and pick it back up whenever.</p><p>So the mechanism for pausing React’s work is almost embarrassingly simple: after finishing each fiber, React checks a clock. “Do I still have time in this ~5-millisecond slice before the browser needs control back?” If yes, keep going. If no, stop the loop, hand control back to the browser (so it can, say, register your keystroke), and later resume the loop starting from that exact same pointer.</p><p>No coroutines. No generators doing anything exotic under the hood. No black magic. Just “the loop stopped, and we remembered which node we were on.” That’s genuinely the whole trick, and it only works *because* the tree is a linked list instead of a call stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*que_67InrA7RsyFzkwe7Tw.png" /></figure><h4>A Concrete Walkthrough</h4><p>Say you’ve got this tree:</p><p>App<br>├── Header<br>├── List<br>│ └── Item<br>└── Footer</p><p>React’s traversal, one fiber at a time:</p><p>1. Start at `App`. It has a child → go to `Header`.<br>2. `Header` has no children. Does it have a sibling? Yes → go to `List`.<br>3. `List` has a child → go to `Item`.<br>4. `Item` has no children and no sibling. Go back up to its parent (`List`). `List` has no more children to process, but *it* has a sibling → go to `Footer`.<br>5. `Footer` has no children, no sibling, and its parent is `App`, which also has nothing left. Done.</p><p>Five fibers, five steps, one pointer moving between them the entire time. If your browser had needed to handle a click after step 2, React would have just… stopped after `Header`, let the browser do its thing, and resumed at `List` a few milliseconds later like nothing happened. The tree didn’t notice. The user definitely didn’t notice — which, ironically, is the whole point. The best UI performance work is invisible.</p><h4>Plot Twist: There Are Actually *Two* Trees</h4><p>Here’s where it gets genuinely clever instead of just “linked lists are neat” (which, sure, they are, but let’s not get carried away).</p><p>React doesn’t build the new tree *on top of* the old one. It keeps two completely separate fiber trees in memory at once:</p><p>- <strong>current</strong>— the fiber tree that matches what’s literally on the screen right now.<br>- <strong>workInProgress</strong> — a brand new tree being built for the <em>next</em> update, using <strong>current</strong> as a reference.</p><p>Each fiber has one more field, `alternate`, which points to its twin in the other tree. When the new tree finishes building, React doesn’t copy anything — it just flips a pointer, and `workInProgress` instantly *becomes* the new `current`. This is called double buffering, and it’s the same idea video games use to avoid screen tearing: build the next frame somewhere off-screen, then swap it in all at once.</p><p>Why does this matter for our pause/resume story? Because it means <strong>the screen is never in a half-updated state</strong>, even while React is mid-build. And it means something even better: if a more urgent update shows up while <strong>workInProgress</strong> is half-built — say, you typed a character — React can just <strong>throw the half-finished tree in the trash</strong> and start a new one for your keystroke, with zero consequences. `current` was never touched. Nothing was corrupted. It’s the computing equivalent of realizing you’re building the wrong LEGO set halfway through and just… starting over, no harm done, because you hadn’t glued anything yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0Qw4_CRnszmPfjsxA-GpA.png" /></figure><h4>So What Do You Actually Get Out of All This?</h4><p>Let’s connect it back to the boring-but-true business value, because “cool linked list” doesn’t pay anyone’s salary:</p><p>- <strong>Typing stays responsive</strong>, even while a big list re-renders in the background, because React can interrupt low-priority work for high-priority input.<br>- <strong>startTransition</strong> and <strong>useDeferredValue </strong>exist <em>because</em> this pause/resume machinery exists — they’re just APIs for telling React “this update can be deprioritized if something more urgent comes up.”<br>- <strong>Concurrent rendering</strong> (the whole reason React 18’s <em>createRoot</em> exists) is built entirely on top of Fiber’s ability to pause, abandon, and resume trees.</p><p>None of this was possible with a recursive call stack. It’s not that the old React team wrote worse code — it’s that recursion is fundamentally the wrong tool for “pausable work,” and no amount of clever engineering fixes that. You have to change the data structure. Which they did. With a linked list. The one from CS101.</p><h4>The One-Paragraph Version, for When Someone Asks You in an Interview</h4><p>Fiber replaced React’s recursive call-stack-based tree walk with an explicit linked list (`child`/`sibling`/`return` pointers) traversed by a loop instead of recursion. This matters because a loop’s progress fits in a single pointer, which can be paused and resumed trivially — unlike a call stack, which can’t be interrupted mid-recursion. React checks a time budget after every fiber and yields control back to the browser when it runs low, resuming later from the same pointer. A second tree (`workInProgress`) is built alongside the visible one (`current`), connected via `alternate` pointers, so an in-progress render can be safely abandoned entirely if something more urgent comes in — without ever corrupting what’s on screen.</p><p>Say that at a whiteboard and watch the interviewer’s eyebrows go up slightly. That’s the “oh, they actually get it” eyebrow raise. You’ll know it when you see it.</p><p>And that’s Fiber — proof that sometimes the most sophisticated-sounding rewrite in software history boils down to “what if, instead of a call stack, we just… used pointers.” Turns out that’s how you build a UI framework that doesn’t ghost you mid-keystroke.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25176dcf94a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>