DIVYA PANDRAJU’s Post

⚛️ When I finally stopped my React component from doing unnecessary math 😅 I was building a dashboard where a small counter update caused my entire expensive calculation to re-run — every. single. time. 🤯 Even though the input didn’t change, React was recalculating it again and again. My poor CPU was screaming! 💻🔥 That’s when I discovered useMemo() — the performance lifesaver I didn’t know I needed. Here’s what I learned 👇 ❌ Before: function Dashboard({ data }) { const total = heavyCalculation(data); return <h1>Total: {total}</h1>; } ✅ After using useMemo(): function Dashboard({ data }) { const total = useMemo(() => heavyCalculation(data), [data]); return <h1>Total: {total}</h1>; } 💡 What useMemo() does: It remembers the result of your calculation until its dependencies change. If nothing changes, it just returns the cached value — no more re-running heavy logic! 🚀 ✨ Lesson learned: Use useMemo() when your function is expensive and your inputs don’t change often. React will thank you with smoother performance! 🙌 #ReactJS #useMemo #ReactHooks #FrontendDeveloper #MERNStack #PerformanceOptimization #WebDevelopment #JavaScript #LearningByDoing #CodingJourney

To view or add a comment, sign in

Explore content categories