React 19.2 just dropped a new <𝗔𝗰𝘁𝗶𝘃𝗶𝘁𝘆> component. Let’s explore what it can do: <𝗔𝗰𝘁𝗶𝘃𝗶𝘁𝘆> is a React component that lets you 𝗵𝗶𝗱𝗲/𝘀𝗵𝗼𝘄 UI components while 𝗽𝗿𝗲𝘀𝗲𝗿𝘃𝗶𝗻𝗴 𝘁𝗵𝗲𝗶𝗿 𝗶𝗻𝘁𝗲𝗿𝗻𝗮𝗹 𝘀𝘁𝗮𝘁𝗲. Instead of completely unmounting components (which destroys their state), it uses 𝗱𝗶𝘀𝗽𝗹𝗮𝘆: 𝗻𝗼𝗻𝗲 to hide them. 𝗞𝗲𝘆 𝗙𝗲𝗮𝘁𝘂𝗿𝗲𝘀: 𝟭. 𝗦𝘁𝗮𝘁𝗲 𝗣𝗿𝗲𝘀𝗲𝗿𝘃𝗮𝘁𝗶𝗼𝗻: When hidden, components keep their React state (like form inputs, expanded sections, etc.) 𝟮. 𝗗𝗢𝗠 𝗣𝗿𝗲𝘀𝗲𝗿𝘃𝗮𝘁𝗶𝗼𝗻: The actual DOM elements stay in the tree, so things like video timecodes or textarea content are maintained 𝟯. 𝗘𝗳𝗳𝗲𝗰𝘁 𝗖𝗹𝗲𝗮𝗻𝘂𝗽: Hidden components have their Effects cleaned up (no active subscriptions), but Effects restart when shown again 𝟰. 𝗣𝗿𝗲-𝗿𝗲𝗻𝗱𝗲𝗿𝗶𝗻𝗴: Hidden components can pre-render at low priority to speed up future interactions 𝗕𝗮𝘀𝗶𝗰 𝗨𝘀𝗮𝗴𝗲: <Activity mode={isVisible ? "visible" : "hidden"}> <MyComponent /> </Activity> 𝗠𝗮𝗶𝗻 𝗨𝘀𝗲 𝗖𝗮𝘀𝗲𝘀: 1. Tab interfaces - Keep form data when switching tabs 2. Sidebars - Preserve expanded/collapsed state 3. Pre-loading - Render heavy components in background 4. Performance - Improve hydration by splitting component tree 𝗜𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝗡𝗼𝘁𝗲𝘀: - Hidden components still re-render (at lower priority) - Effects are cleaned up when hidden, restarted when shown - DOM side effects (like playing videos) persist unless you add cleanup - Works great with Suspense for data fetching 𝗖𝗼𝗺𝗺𝗼𝗻 𝗚𝗼𝘁𝗰𝗵𝗮: If you have DOM elements with side effects (video, audio, iframe), you need to add cleanup Effects to pause them when hidden: useLayoutEffect(() => { return () => videoRef.current.pause(); }, []); It's basically a smarter way to show/hide components. #Nextjs #Reactjs #ReactNative #JavaScript #WebDevelopment #Frontend #FullStack #TypeScript #Programming #Tech #SoftwareEngineer #DevCommunity
Great feature for performance improvement, but for smaller components I will still use '&&' as it is much more readable.
More code, less reward. Would have been better is it used for component level role based access control.
What about component mounting ?
Is this Vue's v-show directive?
More code, same thing 😁
My two cents: it would be even better creating a function like isActiveTab(tabName: string) and return visibility state. That way you encapsulate functionality 😉
More codes
Great
Great info, thx 👏