<?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: Dikson Samuel</title>
    <description>The latest articles on Forem by Dikson Samuel (@dikson_samuel_796bcf3d34f).</description>
    <link>https://forem.com/dikson_samuel_796bcf3d34f</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%2F3700665%2Ffbb883a1-b91b-43df-af39-4f2749acda40.jpg</url>
      <title>Forem: Dikson Samuel</title>
      <link>https://forem.com/dikson_samuel_796bcf3d34f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dikson_samuel_796bcf3d34f"/>
    <language>en</language>
    <item>
      <title>A Deep Dive into React's New &lt;Activity&gt; Component</title>
      <dc:creator>Dikson Samuel</dc:creator>
      <pubDate>Thu, 08 Jan 2026 14:49:02 +0000</pubDate>
      <link>https://forem.com/dikson_samuel_796bcf3d34f/a-deep-dive-into-reacts-new-component-hja</link>
      <guid>https://forem.com/dikson_samuel_796bcf3d34f/a-deep-dive-into-reacts-new-component-hja</guid>
      <description>&lt;p&gt;Have you ever navigated away from a tab in your app, only to return and find your scroll position lost, your input fields cleared, or a loading spinner greeting you all over again?&lt;/p&gt;

&lt;p&gt;Traditionally, React developers have handled "showing and hiding" UI by conditionally mounting or unmounting components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{isShowingSidebar &amp;amp;&amp;amp; &amp;lt;Sidebar /&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While effective, this approach destroys the component state every time it unmounts. In modern React (v19+), there is a better way. Enter the  component.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the  Component?
&lt;/h2&gt;

&lt;p&gt;Formerly known as the "Offscreen" API during its experimental phase,  is a built-in React component that allows you to hide and restore UI without losing its internal state or DOM nodes.&lt;/p&gt;

&lt;p&gt;Instead of removing elements from the tree,  keeps them "alive" in the background but visually hidden.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Basic Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Activity } from 'react';

function App() {
  const [isVisible, setIsVisible] = useState(true);

  return (
    &amp;lt;Activity mode={isVisible ? "visible" : "hidden"}&amp;gt;
      &amp;lt;Sidebar /&amp;gt;
    &amp;lt;/Activity&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Game-Changing Use Cases
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Preserving "Ephemeral" State&lt;/strong&gt;&lt;br&gt;
When you hide a component with &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt;, React doesn't just keep the JavaScript state; it keeps the DOM state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Form Drafts:&lt;/strong&gt; If a user types into a &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;, switches tabs, and comes back, their text is still there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scroll Position:&lt;/strong&gt; No more manual "scroll restoration" logic—the browser naturally keeps the scroll position because the element was never removed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Intelligent Pre-rendering&lt;/strong&gt;&lt;br&gt;
This is where  gets powerful. You can render components that the user hasn't seen yet to make your app feel "instant."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Activity mode="hidden"&amp;gt;
  &amp;lt;SlowComponent /&amp;gt;
&amp;lt;/Activity&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a component is inside a hidden Activity boundary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React renders it at a lower priority, ensuring it doesn't block the main thread.&lt;/li&gt;
&lt;li&gt;It fetches data (if using Suspense-enabled sources like use).&lt;/li&gt;
&lt;li&gt;It skips running Effects (like useEffect) until the component actually becomes visible.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Faster Initial Hydration&lt;/strong&gt;&lt;br&gt;
React uses a technique called Selective Hydration. Usually, this is triggered by . However,  also signals to React that a piece of UI is independent. This allows React to hydrate your "Active" content first, making the page interactive faster, even if the "Hidden" content is complex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does it differ from &lt;code&gt;display: none&lt;/code&gt;?&lt;/strong&gt;&lt;br&gt;
You might be thinking: "Can't I just use CSS &lt;code&gt;display: none&lt;/code&gt;?"&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; does use &lt;code&gt;display: none&lt;/code&gt; under the hood to hide elements, it adds several layers of "React Intelligence":&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Effect Orchestration:&lt;/strong&gt; When mode="hidden", React destroys your &lt;code&gt;useEffect&lt;/code&gt; cleanups and only re-runs them when the component becomes visible. This prevents background components from running timers or subscriptions that eat up resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Priority Management:&lt;/strong&gt; Updates inside a hidden &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; are deprioritized. React won't let a background re-render cause a frame drop in your foreground UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View Transitions:&lt;/strong&gt; It integrates with the View Transition API, allowing for smooth animations when content enters or exits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Caveats ⚠️
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ref Behavior:&lt;/strong&gt; Because the DOM nodes still exist, refs will still point to the hidden elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text Components:&lt;/strong&gt; If your component returns only text (no wrapper div),  won't render anything when hidden because there is no DOM element to apply display: none to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Side Effects:&lt;/strong&gt; If you have side effects that aren't inside &lt;code&gt;useEffect&lt;/code&gt; (like a &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt; tag auto-playing), they might continue to run in the background. Always ensure your components are "well-behaved."&lt;/p&gt;

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

&lt;p&gt;The &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; component is a major step toward "Agentic" UI—where our apps are smart enough to prepare content in the background and remember exactly where the user left off.&lt;/p&gt;

&lt;p&gt;If you’re building complex dashboards, multi-tab interfaces, or performance-heavy web apps, it's time to stop unmounting and start using &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Are you planning to refactor your tabs to use Activity? Let me know in the comments!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>ui</category>
    </item>
  </channel>
</rss>
