🚀 Day 28/30 – useCallback (Stable Function References) Your child component still re-renders… even after using React.memo? 👀 Today I learned why that happens — and how to fix it ⚡ 👉 useCallback 💻 The Hidden Problem: Every render creates a new function reference ❌ That means: 👉 Parent re-renders 👉 New function gets passed as prop 👉 Child sees changed prop 👉 Child re-renders again Even with React.memo 💻 The Solution: Use useCallback ✅ It memoizes functions and keeps the same reference until dependencies change. 💻 Example: import { useState, useCallback } from "react"; const Child = React.memo(({ onClick }) => { console.log("Child Rendered"); return Click; }); function App() { const [count, setCount] = useState(0); const handleClick = useCallback(() => { console.log("Clicked"); }, []); return ( <> <button onClick={() => setCount(count + 1)}> {count} <Child onClick={handleClick} /> </> ); } 🔥 What actually happens: 1️⃣ Parent re-renders 2️⃣ handleClick keeps same reference 3️⃣ Child prop unchanged 4️⃣ React.memo skips child render ⚡ 💡 Why this matters: ✅ Better performance ✅ Fewer wasted renders ✅ Useful in optimized apps ⚡ Real Use Cases: Memoized child components Large lists with actions Dashboard widgets Event handlers passed deeply ⚡ Advanced Insight: Don’t use useCallback everywhere ❌ If no memoized child depends on it, it may add unnecessary complexity. 🔥 Key Takeaway: React.memo protects components. useCallback protects function props. Be honest 👇 Are you using useCallback smartly… or just because tutorials said so? 👀 #React #useCallback #Performance #FrontendDevelopment #JavaScript
Why useCallback Protects Function Props in React
More Relevant Posts
-
🚀 React Child Component Issues – Why Unnecessary Re-renders Happen (and How to Fix Them) One of the most common performance issues in React apps is unnecessary child component re-renders. By default, when a parent component re-renders, React will also re-render its child components — even if the child props have not changed. This can slow down your application, especially in large projects with complex UI trees. ⚡ 🔴 The Problem When state or props change in a parent component: ✔ Parent re-renders ✔ Child components re-render too ❌ Even if child data is exactly the same That means extra rendering work for React and lower performance. ✅ The Solution Use optimization techniques to prevent unnecessary updates: 1️⃣ React.memo() Wrap child components with React.memo() so React only re-renders them when props actually change. const Child = React.memo(({ message }) => { return <p>{message}</p>; }); 2️⃣ useCallback() When passing functions as props, use useCallback() to keep the same function reference between renders. const handleClick = useCallback(() => { console.log("Clicked"); }, []); Without useCallback, a new function is created every render, causing child re-renders. 🎯 Key Benefits ✅ Fewer unnecessary re-renders ✅ Better app performance ✅ Faster UI updates ✅ Smoother user experience ✅ Cleaner optimization strategy 💡 Pro Tip Don’t overuse memoization everywhere. Use it where performance matters — lists, heavy components, dashboards, tables, forms, etc. 🔥 Final Thought React re-renders by design, but smart developers control when it matters. Write optimized React code — your users (and CPU) will thank you. 💙 #ReactJS #ReactDeveloper #JavaScript #FrontendDevelopment #WebDevelopment #ReactMemo #UseCallback #PerformanceOptimization #CodingTips #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 #day44 of #100DaysCodingChallenge ✨ Just Built My ABCD Counting Web App I’m excited to share my latest mini project — an interactive ABCD Counter Website This app helps users learn alphabet counting in a simple and fun way. With just one click, letters move from A → B → C → ... → Z 💡 Tech Used: HTML CSS JavaScript ⚡ Key Features: One-click letter increment Reset functionality Clean and simple UI Beginner-friendly logic 🛠️ Challenges I faced: Handling letter transitions correctly (Z → A) Managing UI updates dynamically Keeping code clean and simple 🎯 What I learned: DOM manipulation Event handling Basic logic building 🔗Github Link : https://lnkd.in/dKUSTb5P #WebDevelopment #JavaScript #Frontend #CodingJourney #BeginnerProject #HTML #CSS #Learning
To view or add a comment, sign in
-
🚀 Excited to share something I built for the React Native community! Over the past 3+ years working with React JS and React Native, I’ve built multiple reusable components to simplify development and maintain consistency across projects. One of those is now published on npm: 👉 react-native-form-textinput This is a TextInput component built specifically to work smoothly with React Hook Form — helping you write less code while handling forms more efficiently. 🔹 What it offers: • Seamless integration with React Hook Form • Reduces boilerplate code in forms • Built-in validation & error handling • Clean and reusable structure • Easily customizable UI I’ve been using this in my own projects, and it has significantly improved development speed and code quality. 🔗 NPM: https://lnkd.in/dV9UyR_G 💻 GitHub: https://lnkd.in/drZ_GM_F I’m planning to improve this package further 🚀 If you have suggestions, ideas, or want to contribute, feel free to open an issue or PR on GitHub. Would really appreciate your feedback 🙌 #ReactNative #JavaScript #OpenSource #NPM #MobileDevelopment #MERN #Developers
To view or add a comment, sign in
-
Project 6/25 — QuizApp (This is where I moved from JavaScript to React) After getting comfortable with HTML, CSS, and JavaScript, I felt ready to try a framework. I chose React. At the time, concepts like props, state, and re-rendering were completely new to me — but I wanted to understand how modern frontend applications are built. So I built a Quiz App. This project was my first real experience with: • Managing state using useState (score, screen flow, user data) • Passing data between components using props • Structuring an app into reusable components (Start, Quiz, Restart) • Controlling UI flow (start → quiz → result) • Using timing/interval logic for user interaction One thing that stood out to me was how React changes your thinking: Instead of manually updating the DOM, you focus on state — and the UI updates automatically. Looking back, this was the project that helped me understand how frontend applications are actually structured. Live demo: https://lnkd.in/dN7eJ_Hb If you’re learning React, what concept was hardest for you at the beginning? #React #FrontendDevelopment #WebDevelopment #BuildInPublic #Project25
To view or add a comment, sign in
-
-
Recently, I revisited some of my earlier React projects and decided to finally share them. Here are a few projects I built while learning: 🔹 To-Do List App A modern task manager with drag-and-drop, dark mode, filtering, and local storage support. 🔹 Weather Dashboard Fetches real-time weather data (temperature, wind speed, conditions) using OpenWeather API. 🔹 FlipMind A card-matching game with smooth animations and responsive design. 🔹 QuoteCraft A minimal quote generator with a clean and simple UI. These projects helped me strengthen my fundamentals in React, state management, and working with APIs. Links are in the comments 👇. #React #WebDevelopment #FrontendDevelopment #JavaScript #LearningJourney
To view or add a comment, sign in
-
🚀 Learning State Management with Zustand (Simple & Powerful) State management is one of the most important concepts in React. Instead of complex setups like Redux, I started exploring Zustand — and honestly, it feels much cleaner and easier. 💡 Why Zustand? Minimal setup (no boilerplate) Easy to understand No providers needed Perfect for small to medium projects 🛒 Built a simple Add to Cart system using Zustand Here’s the idea: ✅ Store structure: cartItems → list of products addToCart → adds or increases quantity decreaseQuantity → reduces quantity removeItem → deletes product completely 🔥 What I learned: How to manage global state without complexity How to handle cart logic (add, remove, quantity) Importance of clean state design demo app https://lnkd.in/gpwwijcc GithubLink: https://lnkd.in/ga-3ag2S #ReactJS #Zustand #StateManagement #WebDevelopment #FrontendDevelopment #JavaScript #MERN #LearningInPublic #BuildInPublic #Ecommerce #CodingJourney
To view or add a comment, sign in
-
-
🪝: Our app was slow. Users were complaining. Here's the 5 things that fixed it (and the 1 thing that almost made it worse). Performance optimisation is one of those things that sounds abstract until you have actual users complaining. Here's what I've done in real projects that actually moved the needle: 1. CODE SPLITTING with React.lazy() → Don't load the whole app on first visit → Lazy load routes and heavy components → Real impact: cut initial load time by ~40% on a large project 2. MEMOISATION — but only where it matters → React.memo() for components that receive the same props often → useMemo() for expensive calculations → useCallback() for functions passed as props → WARNING: Over-memoising adds overhead. Profile first, optimise second. 3. OPTIMISED RENDER CYCLES → Identify what's causing unnecessary re-renders (React DevTools Profiler is your best friend) → Move state as close to where it's used as possible → Avoid storing derived data in state — calculate it 4. IMAGE OPTIMISATION → Lazy load images below the fold → Use appropriate formats (WebP where possible) → Set explicit width/height to avoid layout shifts 5. BUNDLE ANALYSIS → Use webpack-bundle-analyzer or Vite's rollup-plugin-visualizer → You'll be shocked what's in your bundle sometimes The thing that almost made it worse? Premature memoisation everywhere. We wrapped every component in React.memo before profiling. It actually slowed things down. MEASURE. THEN OPTIMISE. What's your go-to performance trick? #ReactJS #PerformanceOptimisation #FrontendDev #JavaScript #WebPerformance #CodeSplitting #ReactHooks
To view or add a comment, sign in
-
🧠 Why key Can Reset Your Entire Component State Most people think key is just for lists. It’s not. 👉 It can force React to destroy and recreate a component. 🔍 Example function App() { const [id, setId] = useState(1); return ( <> <button onClick={() => setId(id + 1)}>Next</button> <Profile key={id} /> </> ); } What happens? Every time id changes: 👉 React sees a new key 👉 It unmounts old component 👉 It creates a new one 💥 Result Inside Profile: const [count, setCount] = useState(0); 👉 count resets to 0 every time 🧠 Why? Because React thinks: “This is a completely new component” 🎯 Real use case You can use this intentionally: Reset form state Restart animations Clear component data 💥 Hidden danger Using unstable keys (like Math.random() or index) 👉 Can cause unexpected resets 👉 Leads to weird bugs 🧠 Final Insight key doesn’t just help React track elements It controls component identity #ReactJS #FrontendDevelopment #JavaScript #ReactTips #WebDevelopment #CleanCode #LearningInPublic
To view or add a comment, sign in
-
🔍 Your React app feels slow… where do you even start? Here’s the exact process I follow 👇 🧪 Step 1 — React DevTools Profiler Open it → hit record → reproduce the slow interaction Look for: • Long bars • Unexpected grey “did not render” gaps • Commits taking >16ms 🎨 Step 2 — "Highlight updates" toggle Turn it on. Now every re-render flashes on screen ✨ 👉 If your whole UI lights up when typing one character …you’ve found a problem. 🧰 Step 3 — why-did-you-render Install it: npm install @welldone-software/why-did-you-render It logs unnecessary re-renders + the reason behind them. Think of it as: 🧠 console.log for performance bugs 📊 Step 4 — Chrome DevTools Performance tab Use it for deeper analysis: • Paint • Layout • Scripting Look for: 🚨 Long tasks (red triangles) ⚠️ The order matters: Don’t jump to useMemo before running the Profiler. You’ll end up optimizing the wrong thing. 🧠 Better approach: Find the problem → Understand the cause → Fix it specifically #ReactJS #Performance #FrontendDevelopment #Debugging
To view or add a comment, sign in
-
useCallback doesn't actually make your app faster I see devs wrap every callback in useCallback thinking it's a performance optimization. But here's the truth: The trade-off: - useCallback has overhead (memory + complexity) - Only worth it if child component is wrapped in React.memo() - Most apps don't need it Real performance issues: - Too many DOM nodes (not callbacks) - Inefficient state updates (batching issue) - Expensive computations (use useMemo instead) - Missing keys in lists (array render issue) I spent 2 weeks optimizing callbacks in PulseStack. Removed 80% of them. Result? No performance change. What changed performance was fixing my list rendering and state update batching. the lesson i learn is Profile your code before optimizing. Don't optimize blindly. happy to hear your pov 🙂 too ! , i am also here to learn ✨ from you guys . #React #Performance #JavaScript #WebDevelopment #FrontendOptimization
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