𝗗𝗮𝗻𝗴𝗲𝗿𝗼𝘂𝘀 𝗥𝗲𝗮𝗰𝘁 𝗵𝗮𝗯𝗶𝘁 𝗶𝗻 𝟮𝟬𝟮𝟲: 𝗣𝘂𝘁𝘁𝗶𝗻𝗴 𝗵𝗲𝗮𝘃𝘆 𝗰𝗼𝗺𝗽𝘂𝘁𝗮𝘁𝗶𝗼𝗻𝘀 𝗱𝗶𝗿𝗲𝗰𝘁𝗹𝘆 𝗶𝗻 𝗿𝗲𝗻𝗱𝗲𝗿(). It kills performance and makes debugging painful. Better way: Move them to useMemo(). Old way: return expensiveCalculation(props.data); New way: const result = useMemo(() => expensiveCalculation(props.data), [props.data]); Simple fix, huge impact. What’s one React mistake you fixed recently? Building something performant? My gig: https://lnkd.in/gixh_dTi #ReactJS #JavaScript #FrontendDevelopment
Optimize React Performance with useMemo
More Relevant Posts
-
💡 𝐑𝐞𝐚𝐜𝐭 𝐂𝐨𝐧𝐜𝐞𝐩𝐭 – 𝐏𝐫𝐨𝐩𝐬 ❓ Ever wondered how 𝐝𝐚𝐭𝐚 𝐟𝐥𝐨𝐰𝐬 between components in React? Today I learned about 𝐏𝐫𝐨𝐩𝐬, a core concept that makes React components reusable 🚀 🔹 Props are used to 𝐩𝐚𝐬𝐬 𝐝𝐚𝐭𝐚 𝐟𝐫𝐨𝐦 𝐩𝐚𝐫𝐞𝐧𝐭 𝐭𝐨 𝐜𝐡𝐢𝐥𝐝 𝐜𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭𝐬 🔹 They help build 𝐝𝐲𝐧𝐚𝐦𝐢𝐜 & 𝐫𝐞𝐮𝐬𝐚𝐛𝐥𝐞 𝐔𝐈 🔹 Props are 𝐫𝐞𝐚𝐝-𝐨𝐧𝐥𝐲 (cannot be modified by child component) In the attached example, name is passed as a 𝐩𝐫𝐨𝐩 from parent to child component 👇 What should I share next — useEffect with API call or custom hooks? 🤔 #ReactJS #JavaScript #Props #FrontendDevelopment #LearningInPublic #ReactDeveloper
To view or add a comment, sign in
-
-
React Optimization: useMemo() hook.. Why first code in the image fails: In JavaScript, objects are compared by reference, not value. Even though { color: 'red' } looks the same as the previous render, React sees a new memory address. 👉 Result: The useEffect thinks options has changed and fires on every single render. You just created an infinite loop or an API spammer. Why the code below works: useMemo tells React: "Keep this object at the same memory address unless dependencies change." 👉 Result: The useEffect sees the exact same reference and skips the re-run. 💡 The Lesson: Don't just ask "Is this function heavy?" Also ask: "Am I passing this object/array into a dependency array?" If the answer is yes, you need useMemo to stabilize it. #ReactJS #WebDevelopment #JavaScript #CodingTips #FrontendEngineering
To view or add a comment, sign in
-
-
React Deep Dive – Day 13 Today I revisited useEffect, specifically how easily it can become a source of unnecessary work. What I revisited today: 1. Not every side-effect belongs in useEffect 2. Effects re-run whenever dependencies change, sometimes more often than expected 3. Deriving state inside effects often leads to extra renders 4. Missing or incorrect cleanup can cause subtle bugs over time In practice: 1. Effects should model external interactions, not internal data flow 2. Many effects can be replaced with derived values during render 3. Cleanup logic matters just as much as the effect itself 💡 My takeaway: A good useEffect is boring. If it’s doing too much, it’s probably doing the wrong thing. Continuing this React Deep Dive, refining habits that keep components predictable as they grow. Day 14 next. #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #LearningInPublic
To view or add a comment, sign in
-
Can you actually solve this Node.js event loop question? No running the code. No guessing. Just reasoning. I’m sharing a short Node.js snippet Your task is simple , but not easy 👇 Predict the exact output order Assume this runs in Node.js, not the browser Timers, Promises, nextTick, I/O, setImmediate are all involved One wrong assumption and the output breaks Most people get confident… then get it wrong The trick is not memorising order The trick is knowing when micro tasks interrupt phases And why poll vs check matters If you can explain why each line runs where it does, you actually understand the event loop. What’s the final output order? Drop it in the comments. #NodeJS #JavaScript #EventLoop #BackendInterviews #InterviewPrep #FullStack #SystemDesign
To view or add a comment, sign in
-
-
const user = { name: 'Munsif', print: () => console.log(this.name) }; user.print(); If you think it prints "Munsif"... we need to talk. The `this` keyword is the silent killer of clean code. It changes based on *how* you call it, not *where* you write it. I just dropped a massive deep dive on my blog: "Demystifying the JavaScript 'this' Keyword." I peel back the layers on: 🔹 The 4 binding rules every dev must memorize 🔹 The exact reason the code above fails (and how to fix it) 🔹 The magic of `.bind()`, `.call()`, and `.apply()` 🔹 Tricky interview questions that trip everyone up Don't let context bugs haunt your PRs anymore. Link to the full breakdown: https://lnkd.in/gWMGP5Kn (The answer to the snippet is `undefined`. My blog explains why! 😉) #JavaScript #CodingChallenge #Frontend #DeveloperLife #JS
To view or add a comment, sign in
-
-
👋 Hello! 🌱🪝Today I have gone through the one of most usable and necessary Hook i.e. 'useEffect' Hook. =>This useEffect hook will help us to do some side effect in our component such as fetching data, Updating the DOM, setting timers it runs automatically based on the dependencies we provide. useState =>Store data (users + loading). useEffect =>Run API call when component loads. fetch() => Get data from an API. loading =>Show message until data arrives. catch() => Handle errors. finally() =>Stop loading. map() =>Display each user. #ReactJS #useState #frontendDevelopment #Javascript #Learningjourney.
To view or add a comment, sign in
-
-
Ever wondered why useEffect runs twice and thought: “React is broken”? It’s actually doing you a favor. In development, React deliberately re-runs effects to expose: - Hidden side-effects - Missing cleanups - Unsafe logic This behavior occurs in Strict Mode and does not affect production. Once you understand this, you can stop fighting React and start writing effects that are predictable, clean, and future-proof. React isn’t trolling you; it’s training you. #React #ReactHooks #Frontend #JavaScript #WebDevelopment
To view or add a comment, sign in
-
-
React performance tip that actually matters 🚀 Most re-render issues come from: ❌ Passing new objects/functions in props ❌ Unstable dependencies ❌ Unnecessary state Fix it with: ✅ memoization (when needed) ✅ stable handlers ✅ derived state 💬 Have you debugged re-renders before? Hashtags: #ReactJS #WebPerformance #FrontendEngineering #JavaScript #SoftwareDeveloper
To view or add a comment, sign in
-
🧠⚡ Microtasks vs Macrotasks: Mastering the JavaScript Event Loop JavaScript isn’t just single-threaded — it’s precisely orchestrated. Behind every Promise, async/await, and setTimeout lies the event loop that decides what runs first and why. 🔹 Why Promises feel “immediate” 🔹 Why setTimeout(fn, 0) still waits 🔹 How microtasks guarantee atomic async flows 🔹 Why macrotasks keep browsers responsive Once you understand the two-queue model, async bugs stop being “mysteries” and start being predictable behavior. If you write JavaScript, this mental model is non-negotiable. 🚀 👉 Read the full deep dive here - https://lnkd.in/gBweAVaX #JavaScript #EventLoop #Microtasks #Macrotasks #AsyncAwait #Promises #WebPerformance #Frontend #NodeJS #SoftwareEngineering
To view or add a comment, sign in
-
-
💡 Nest.js vs Express.js — Structure vs Freedom As developers, one of our most critical decisions is choosing the right framework. 🔹 Express.js gives you complete freedom and flexibility. You can build anything—but the entire architecture is in your hands. 🔹 Nest.js provides a clean, scalable structure from day one—ideal for enterprise-level applications. When projects grow, structure defeats chaos. When speed matters, flexibility wins. There's no "one size fits all"—only the right tool for the right use case. #Backend #Development #NestJS #Expressjs #coding #javascript #code231
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