🚀 My component rendered 17 times… for a single click. Do you know why? Was debugging a product listing page recently. Changed one filter… and React decided to re-render the list 17 times. UI wasn’t broken, but it felt slightly off. ~200–300ms delay on interaction. Not huge… but noticeable. Checked profiler → turns out a lot of unnecessary work. Main issues: • Parent state change → whole list re-render • Inline onClick → new function every time • Some data transformations running again and again • No memoization anywhere One example 👇 <ProductCard onClick={() => handleClick(id)} /> This looks harmless, but it creates a new function on every render. So React thinks props changed → re-render. ✅ Fixed it with useCallback. Another thing I noticed: Even though filtering was handled by API, we were still doing small stuff on frontend like: const enriched = products.map(...) Individually cheap… but with multiple re-renders, it adds up. ✅ Wrapped it in useMemo. ✅ Also wrapped list items with React.memo ✅ After fixes: • 17 renders → 3 • ~150ms → ~35ms UI feels much smoother now (especially on slower devices) Takeaway: Most of the time, performance issues are not “big problems” It’s small things… happening multiple times. If you haven’t checked your components in React Profiler yet, do it once. You might be surprised 😄 #reactjs #javascript #frontend #webperformance #optimization
React Performance Optimization: 17 Renders to 3
More Relevant Posts
-
🚀 𝐓𝐡𝐞 𝐌𝐨𝐦𝐞𝐧𝐭 𝐑𝐞𝐚𝐜𝐭 𝐂𝐨𝐧𝐭𝐞𝐱𝐭 𝐅𝐢𝐧𝐚𝐥𝐥𝐲 “𝐂𝐥𝐢𝐜𝐤𝐞𝐝” 𝐟𝐨𝐫 𝐌𝐞 I was building a simple dark/light theme feature. Sounds easy, right? Until my component tree started looking like this: App → Layout → Header → Toolbar → Button And I was passing theme through every single level. Even components that didn’t care about the theme had to accept it… just to pass it down. That’s when I realized — this isn’t scalable. This is prop drilling. 🧠 The Turning Point: React Context Instead of threading props manually through the tree, I used the Context API. Conceptually, Context works like a broadcast system: 1️⃣ createContext() → creates a shared container 2️⃣ <Provider> → supplies the value at a higher level 3️⃣ useContext() → consumes it anywhere below No more unnecessary prop forwarding. 🔬 𝐓𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥 𝐃𝐞𝐭𝐚𝐢𝐥 𝐓𝐡𝐚𝐭 𝐌𝐨𝐬𝐭 𝐁𝐞𝐠𝐢𝐧𝐧𝐞𝐫𝐬 𝐌𝐢𝐬𝐬 React compares Provider values using Object.is. If you pass a new object literal like: <𝑃𝑟𝑜𝑣𝑖𝑑𝑒𝑟 𝑣𝑎𝑙𝑢𝑒={{ 𝑡ℎ𝑒𝑚𝑒: "𝑑𝑎𝑟𝑘" }} /> Every render creates a new reference → all consumers re-render. The better approach? Store the value in state Or memoize it This small detail makes a big difference in performance. 🎯 When Context Makes Sense ✔ Theme ✔ Auth state ✔ Language ✔ Global UI configuration But Context isn’t a replacement for props. It’s a tool for shared, cross-cutting state. The real lesson? Good React architecture isn’t about avoiding props. It’s about knowing when to elevate state and when to broadcast it. #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #SoftwareArchitecture #WebDevelopment
To view or add a comment, sign in
-
-
Stop Wasting Re-renders: Debounce vs Throttle Have you ever built a search bar that sends an API request on every keystroke? Or added a scroll listener that suddenly makes the UI feel laggy? If you’re not controlling how often a function runs, you’re leaving serious performance gains on the table. Let’s simplify two powerful techniques every frontend developer should know. 👇 ⏱️ Debouncing — “Wait until things stop” Debouncing delays execution until the user stops triggering the event. Think of it like an elevator. It waits for the last person to enter. If someone else jumps in, the timer resets. The elevator moves only when no one else is coming. Best used for: 🔍 Search inputs (run API call after typing stops) 💾 Auto-saving drafts 📏 Window resize handlers 🌊 Throttling — “Run at a steady rate” Throttling ensures a function runs at most once every X milliseconds, no matter how often the event fires. Think of a dripping faucet. No matter how much water pressure there is, it releases one drop at fixed intervals. Best used for: 📜 Infinite scroll checks 🎮 Game controls 🖱️ Mouse / scroll animations 🔍 Quick Comparison Feature Debounce Throttle Goal Run after activity stops Run at fixed intervals Best for Input-heavy events Continuous events Execution Once (after pause) Multiple times (spaced out) 🛠️ Pro Tip In production, don’t reinvent the wheel. Libraries like Lodash make this extremely simple: import { debounce, throttle } from "lodash"; Or build custom React hooks to keep your components clean and optimized. 💬 Question for developers: Which one do you use more in real projects — Debounce or Throttle? Drop your answer in the comments 👇 #WebDevelopment #ReactJS #JavaScript #FrontendDevelopment #PerformanceOptimization #CodingTips #SoftwareEngineering
To view or add a comment, sign in
-
-
120 re-renders → 8 re-renders. Same UI. Same API. Same components. No backend change. No infrastructure change. Just one React concept many developers underestimate. A dashboard I worked on started feeling slow whenever someone typed in the search field. Every keystroke caused the entire page to update — tables, charts, filters, and widgets. So we checked the React DevTools Profiler. Result: ~120 component re-renders for a single keystroke. The API wasn’t the issue. The problem was unnecessary re-renders in the component tree. The root cause A parent component was creating new function references on every render. Example: handleSearch = (value) => { setSearch(value) } Each render created a new function, so React assumed the props changed and re-rendered child components. The fix We stabilized the function reference using useCallback: handleSearch = useCallback((value) => { setSearch(value) }, []) We also applied: • React.memo for heavy components • useMemo for expensive calculations Result 120 re-renders → 8 re-renders Typing became instant. Same UI. Same logic. Just better render control. 💡 Most React performance problems aren’t caused by React itself — they come from how we manage props, state, and re-renders. What React performance issue took you the longest to debug? #React #Frontend #WebPerformance #JavaScript #SoftwareEngineering #WebDevelopment
To view or add a comment, sign in
-
This is probably my last post as a premium member. I have exhausted my possibilities. Before I go, I want to share my vision with you. For it is written: Sow your seed in the morning... I’ve spent years building software and complex UIs, and if there’s one pattern I keep coming back to for pure, decoupled elegance, it’s the Event-Bus. In most frameworks, we spend half our time "prop-drilling" or fighting deeply nested component trees. But with an Event-Bus, things just feel… natural. People often fear that losing a rigid hierarchy means losing control. I see it differently. If two components can't be brought together easily, (which happens naturally when you follow the pattern) you simply define a Contract. By defining a clear technical contract for your events (Inputs/Outputs; Consumer/Bridge), you ensure that your modules stay independent but perfectly synced. You get the safety of a framework with the freedom of Vanilla JS. Components don't need to know who else exists. They just shout their status into the bus ("I just updated!") or listen for what they need. It’s a pub/sub conversation that allows your app to grow without becoming a "spaghetti" mess. Check out my VanillaSPA Micro-Framework: https://lnkd.in/dbUn-3C8 It is optimized for agentic AI native Vibe engineering on your CLI, clearing the way for whatever you want to build. maybe a futuristic Operation System? Are you still nesting everything, or have you moved to a message-driven architecture? Let’s talk in the comments! 👇 #WebDev #JavaScript #SoftwareArchitecture #VanillaJS #CleanCode #EventBus #Frontend #CodingTips
To view or add a comment, sign in
-
-
In React, I keep seeing this idea: “replace state with refs for better performance.” Refs don’t solve performance problems. ✅ useRef updates do not trigger a re-render. So the moment you need to display that value or react to it in the UI, you end up adding extra code to force a re-render (proxy state, events, hacks…). Result: more complexity, harder debugging, and often worse performance. Real React performance comes from: 1. Use selectors to subscribe to only what you need Redux / Zustand / Jotai / React Query / Context… doesn’t matter. The goal is the same: each component should read the smallest slice of data it needs. → fewer unnecessary re-renders, more predictable UI. 2. Minimize heavy components on the page Classic example: a list with edit modals. ❌ Bad: one modal per row 100 rows = 100 modals mounted More memory, more listeners, more props updates → performance pain. ✅ Better: a single modal Keep a selectedItemId (or selected item) and update the modal content based on selection. Cleaner code, scalable, and much faster. Performance isn’t about avoiding renders at all costs. It’s about controlling what re-renders, when, and why. #react #frontend #performance #javascript #webdev
To view or add a comment, sign in
-
A React page once became frustratingly slow in production. Scrolling felt laggy. Clicks had a visible delay. The UI looked fine, but it did not feel fine. My first assumption was the API. But after checking the network tab, the backend was not the issue. Most requests were finishing in under 150ms. The real problem was rendering. The page showed a large list of items, and every small state update was causing the entire list to re-render. After 𝗽𝗿𝗼𝗳𝗶𝗹𝗶𝗻𝗴 𝘁𝗵𝗲 𝗽𝗮𝗴𝗲, the root cause was surprisingly small: An unstable object prop was being recreated on every render and passed down to child components. Something as simple as this was enough: `const itemProps = { price, stock }` The values were the same, but the object reference was new every time. So React treated the child props as changed and re-rendered far more than necessary. The fix was straightforward: • memoize derived props with `useMemo` • wrap expensive list items with `React.memo` • avoid recreating objects and inline callbacks unless needed After the change, render time dropped significantly and the page felt smooth again. Big takeaway - A lot of React performance issues are not caused by slow APIs. They come from unnecessary re-renders and unstable references. Frontend performance gets much easier to debug once you stop asking only "why is this slow?" and start asking "what is re-rendering, and why?"
To view or add a comment, sign in
-
-
𝗧𝗵𝗶𝘀 𝗜𝘀 𝗕𝗹𝗼𝗸𝗝𝗦 Meet BlokJS, a reactive UI framework. It is 9 KB, has no build step, and is standalone. You can use it for your frontend needs. When you start a new project, you usually spend a lot of time setting things up. You install Node, pick a bundler, configure TypeScript, and more. With BlokJS, you can skip all that. You just need one script tag. Here are the key ideas behind BlokJS: - No build step is required - It has everything you need, but it is not bloated - It is simple and easy to use BlokJS updates the DOM directly. It does not use a virtual DOM. This makes it fast and predictable. Let's look at a simple example. We can create a counter with just a few lines of code. You can use BlokJS for your projects. It is great for prototypes, internal tools, and small to medium apps. You can also use it to learn about reactive UI frameworks. To get started with BlokJS, you can use the CDN or install it with npm. Source: https://lnkd.in/gkd9t9ZF
To view or add a comment, sign in
-
🚀 Project Spotlight: Building a Scalable File Management UI with React Recently, I worked on implementing a **dynamic file type management interface** using React. The goal was to create a clean and efficient UI where users can manage file types and mappings easily. 🔧 Tech Stack • React.js • JavaScript (ES6+) • Redux for state management • Reactstrap & React Select for UI components ✨ Key Features Implemented ✔ Dynamic data table with row selection ✔ Conditional UI rendering based on user actions ✔ Responsive UI for different screen sizes ✔ Reusable components for scalability 📚 Useful resources that helped during development: React Documentation https://react.dev/learn Redux Documentation https://lnkd.in/gPJmkbfu JavaScript Guide (MDN) https://lnkd.in/ge3KVDws 💡 What I learned from this project: • Importance of clean state management • Writing reusable and scalable UI components • Handling complex UI interactions efficiently Always exciting to keep improving as a developer and building better user experiences. #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #SoftwareEngineering #ReactDeveloper
To view or add a comment, sign in
-
🚀 Day 24 — Optimizing React Performance with Memoisation As applications scale, performance becomes an architectural concern — not just a functional one. Today, I focused on optimizing rendering behavior in React using memoisation patterns with useMemo and useCallback. When filtering, searching, or sorting large datasets, unnecessary recalculations can silently degrade performance. Memoisation ensures computations only run when truly required. 🔹 1️⃣ useMemo() — Caching Computed Values useMemo stores the result of an expensive computation and recomputes it only when its dependencies change. Best used for: Filtering large product lists Derived state calculations Sorting datasets Transforming API responses Example: const filteredProducts = useMemo(() => { return products.filter(p => p.title.includes(search)); }, [products, search]); This prevents recalculating filters on every render cycle. 🔹 2️⃣ useCallback() — Stabilizing Function References While useMemo caches values, useCallback caches function instances. This is crucial when passing callbacks to child components. Without it, new function references can trigger unnecessary child re-renders. Best used for: Event handlers passed as props Optimized child component rendering Preventing avoidable reconciliation cycles Example: const handleSearch = useCallback((value) => { setSearch(value); }, []); 🔹 Real-World Application — Product Filtering Scenario In a product gallery built using the Fake Store API, memoisation ensures: • No redundant filtering logic • No repeated heavy computations • No unnecessary child re-renders Result: A smoother, more responsive UI — especially as data size grows. 🧠 Key Engineering Insight Performance optimization in React is about: Controlling recalculation Managing reference equality Reducing render frequency Designing predictable dependency graphs Memoisation is not about premature optimization — it is about intentional rendering control. Onward to Day 25 🚀 💬 For frontend engineers: At what scale do you start introducing memoisation patterns in your applications? #ReactJS #FrontendDevelopment #ReactHooks #PerformanceOptimization #SoftwareEngineering #JavaScript #WebDevelopment #100DaysOfCode
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