How React's <Activity> Component Works

⚛️ Why React’s <Activity> Component Is a Game-Changer React just introduced something super interesting: the <Activity> component — and it can completely change how we hide & show UI. ⚡ Normally, when we hide UI using CSS (display: none), the UI disappears but its effects & subscriptions stay active. This causes side effects, memory leaks, or unnecessary updates. React’s new <Activity> component fixes this in a smart way. Here’s what it actually does: 🔥 1. Hides UI visually + cleans up Effects When an Activity boundary is hidden: ✔️ React hides the UI (display: none) ✔️ Destroys Effects (API calls, subscriptions, listeners) ✔️ Frees resources 🔥 2. Still keeps UI state in the background Even though it’s hidden: ✔️ Component state is preserved ✔️ Components still re-render when props change (low priority) That means hidden UI stays “alive”, but quietly. 🔥 3. Restores UI instantly when visible When the Activity becomes visible again: ✔️ UI returns instantly ✔️ Previous state restored ✔️ Effects re-created No need to re-fetch or re-initialize everything. 🧠 In simple words: <Activity> lets you hide components without tearing them down completely — perfect for sidebars, tabs, drawers, or multi-step screens. 💻 Example: <Activity mode={isShowingSidebar ? "visible" : "hidden"}> <Sidebar /> </Activity> 🎯 Why developers love it? • Faster UI switching • Preserved state • No unnecessary side-effects • Better performance for complex apps Would you use <Activity> in your React app? For which feature? #ReactJS #MERNStack #WebDevelopment #FrontendEngineering #React18 #JavaScript

  • text

To view or add a comment, sign in

Explore content categories