If you hide a component using {isVisible && <Component />}, React removes it from the tree, so you lose its state. If you hide it with CSS (display: none), it stays mounted, meaning timers and effects keep running, which hurts performance. Now with <Activity />, React offers a smarter approach: The UI is hidden. The component’s state remains intact. Background work (timers, subscriptions, etc.) is automatically paused. 👉 Think of it like browser tabs — when you switch tabs, the inactive one pauses but keeps its data safe, so when you return, it picks up right where you left off. ⚡ Perfect for: • Tabbed interfaces • Multi-step forms • Complex UIs where hidden parts should pause, not reset #React #ReactJS #ReactDevelopers #WebDevelopment #Frontend #FrontendDevelopment #JavaScript #Coding #Programming #WebDev #SoftwareEngineering #UIUX #CodeTips #DevCommunity #CleanCode #WebDesign #TechTips #DeveloperLife #ReactHooks #ReactComponents
How to Pause React Components with Activity
More Relevant Posts
-
⚛️ React Just Made Form Actions Way Cleaner React’s new hook — useActionState — is a game-changer for handling async form submissions. No more juggling useState, useEffect, or endless try/catch blocks. 🙌 Here’s what it does 👇 🧩 You pass it: A form action (e.g., addToCart) An initial state It gives you back three things: 1️⃣ The latest state (e.g., message or result) 2️⃣ A wrapped action (formAction) 3️⃣ A flag showing if it’s still running (isPending) Now your form logic becomes simpler, more declarative, and easier to read. Just write the action, hook it up, and React handles the rest. It’s a small addition but one that makes a big difference in building clean, async-ready UIs. ⚡ 💬 Have you tried useActionState yet? What’s your take on React’s direction with these new declarative patterns? #ReactJS #JavaScript #WebDevelopment #Frontend #ReactHooks #CleanCode #AsyncProgramming #DeveloperExperience #SoftwareEngineering #CodingTips #ReactDevelopers #DevCommunity #UIUX
To view or add a comment, sign in
-
-
⚛️ A small React concept that makes a big difference — Custom Hooks Ever noticed how Components start getting messy when they handle too much state or logic? ✅ Api Calls ✅ Toggles ✅ Timers ✅ Scroll or Resize Listeners ✅ Form Logic Instead of repeating the same code everywhere, just extract it into a Custom hook. Cleaner components, Reusable logic, Fewer bugs. e.g.: function useToggle(initial = false) { const [value, setValue] = useState(initial); const toggle = () => setValue(v => !v); return [value, toggle]; } // const [open, toggleOpen] = useToggle(); Suddenly your component becomes lighter, readable, and scalable. You can combine multiple hooks and get a polished UI without clutter. If you're a beginner: ➡️ Learn custom hooks early ➡️ Your future self will thank you What’s the coolest custom hook you’ve built or used recently? 🚀 #reactjs #javascript #frontend #webdev #reacthooks #cleancode #programmingtips #buildinpublic
To view or add a comment, sign in
-
React has grown beyond just “a UI library.” Modern React development isn’t just about components anymore. It’s about architecture: Hooks that make complex logic reusable Server & client boundaries (with frameworks) Lightweight state management with tools like useReducer or context Optimizing rendering & avoiding re-renders for performance gains The best React apps today are: ✅ Modular ✅ Performant ✅ Easy to scale A clean component tree + smart state strategy can make more difference than any “fancy optimization.” #ReactJS #WebDevelopment #JavaScript #Frontend #WebDev #DeveloperLife #Programming #UI #TechTrends #React
To view or add a comment, sign in
-
-
⚛️ React never stops amazing me! Every time I dive deeper, I find new techniques that make building UIs smoother, faster, and more enjoyable. Some of my personal favorites lately: ✨ Component composition – Crafting small, reusable pieces that come together beautifully. ⚙️ Custom hooks – Turning repeated logic into clean, shareable functions. 🎯 Performance optimization – Using memo, useCallback, and lazy loading the smart way. 🧩 Context patterns – Managing app-wide state without unnecessary re-renders. 🚀 Code splitting – Keeping apps lightweight and fast with dynamic imports. React is not just a library — it’s a mindset of modular, declarative, and flexible development. What’s your favorite React trick or pattern that makes your code shine? 💬 #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #ReactHooks #Coding #SoftwareEngineering #UIUX #DevCommunity
To view or add a comment, sign in
-
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
To view or add a comment, sign in
-
-
🎲 Built a Random Number Generator using React Class Components! I'm exploring how state works in React and how components re-render dynamically. ⚡ What I learned today: 🔸 Updating state using setState 🔸 Generating dynamic values with Math.random() 🔸 Writing clean & structured class components 🔸 Styling components for a smooth UI ✨ ✨ Features: ✔ Generates a new random number instantly 🎰 ✔ Clean & simple UI ✔ Great practice for understanding React re-rendering Excited to continue improving and building more interactive components! 💻🔥 #ReactJS #Frontend #WebDevelopment #LearningJourney #JavaScript Meghana M 10000 Coders
To view or add a comment, sign in
-
⚛️ React Component Lifecycle — the hidden rhythm behind every UI. Every React component has a journey — from being created, shown, updated, and finally removed. Understanding this lifecycle helps you write cleaner, faster, and more predictable React code. --- 🧩 What is the Component Lifecycle? The lifecycle represents different stages a component goes through during its existence — like Mounting, Updating, and Unmounting. Each stage gives us hooks (or class methods) to run code at just the right moment. --- 🔹 1. Mounting — This is when your component first appears on the screen. You usually fetch data, set up event listeners, or initialize states here. In React hooks: useEffect(() => { console.log("Component mounted!"); }, []); --- 🔹 2. Updating — When something changes. Whenever props or state update, React re-renders your component. You can track or respond to these changes here. In hooks: useEffect(() => { console.log("Component updated!"); }); --- 🔹 3. Unmounting — When the component says goodbye. When the component is removed from the DOM — clean up everything here: cancel API calls, remove listeners, clear timers, etc. In hooks: useEffect(() => { return () => console.log("Component unmounted!"); }, []); --- 💡 Why does it matter? ⚙️ Performance — Run logic only when needed. 🧹 Clean Side Effects — Avoid memory leaks or unwanted API calls. 🔍 Debugging — Know when and why your component re-renders. 🧠 Deeper React Insight — Understand how your app truly “lives” on the browser. --- React’s lifecycle isn’t just theory — it’s the heartbeat of every interactive experience. Once you understand it, your components won’t just work — they’ll feel alive 💙 #react #javascript #frontend #webdevelopment #coding #learning
To view or add a comment, sign in
-
-
Front-end development has been a journey of constant learning, patience and iteration. What started as basic HTML and CSS experiments has evolved into building interfaces that people actually use. Over time I have learned that good UI isn’t just about code it’s about thinking in terms of experience, accessibility, performance and clarity 🎯 There are days of excitement when a feature works exactly as imagined and days of debugging where a missing semicolon can cost hours. But every step successful or frustrating adds up. Front-end development keeps reminding me that growth in tech is not a onetime achievement it’s a continuous habit of improving one commit at a time 💻✨ #frontenddevelopment #webdevelopment #reactjs #javascript #learninginpublic #uiux #consistency #devjourney #codinglife
To view or add a comment, sign in
-
-
🎯 If you’re just starting with Frontend — follow these 11 rules: 1️⃣ Learn HTML, CSS, JS — not frameworks first. 2️⃣ Understand how browsers render pages. 3️⃣ Write code that’s readable, not just runnable. 4️⃣ Master flexbox and grid — layouts make or break UIs. 5️⃣ Learn Git — version control is your best friend. 6️⃣ Focus on core React/Vue/Angular concepts, not shortcuts. 7️⃣ Debug often — that’s where real learning happens. 8️⃣ Build side projects. Even small ones. 9️⃣ Learn to read docs, not just blogs. 🔟 Don’t ignore accessibility — design for everyone. 1️⃣1️⃣ Keep your curiosity alive — the tech will keep changing. Frontend isn’t about writing pretty code — it’s about creating great experiences. 💻✨ #Frontend #WebDevelopment #JavaScript #React #LearningJourney #Coding
To view or add a comment, sign in
-
Advanced States in React.js useMemo and useCallback. React Hooks make our components cleaner, reusable, and easier to manage. They allow us to use state and other React features without writing a class. Two powerful hooks for performance optimization are useMemo and useCallback. 🔹 useMemo: Memoizes a value Use it when you have a heavy calculation that you don’t want to recompute on every render. const result = useMemo(() => { return expensiveCalculation(data); }, [data]); 🔹 useCallback: Memoizes a function Useful when passing functions to child components to prevent re-renders. const handleClick = useCallback(() => { console.log("Clicked!"); }, []); These hooks don’t always need to be used — but when your component re-renders often, they can significantly improve performance and stability. #React #JavaScript #WebDevelopment #Frontend #ReactJS #CleanCode #Programming #Developers #NextJS
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development