Core mental model of useMemo() 💡 ➡️ It takes a pure function as the first argument and a dependency array as the second. ➡️ That function returns a value, and React reuses the previously cached result on later renders if the dependencies have not changed. ➡️ If the returned value is a primitive, React reuses the same value 🧠 This is commonly useful for expensive calculations. ➡️ If the returned value is an object or array, React reuses the same reference 🧠 This is commonly useful for stabilizing props passed to a memoized component created with React.memo() #javascript #typescript #react #useMemo() #memorization
React useMemo() with Pure Function and Dependency Array
More Relevant Posts
-
⚠️ Common Confusions about Control Flow : Switch case: switch-case executes all cases after a match unless you break. else if : else if chain works top-down — order matters. You can use truthy/falsy values directly in if . 🧠 Mindset Control flow = conditional storytelling. It helps your program make choices and respond differently to different inputs. Write readable branches. Avoid nesting too deep — use early return if needed. #react #javascript #JS #ABK #code
To view or add a comment, sign in
-
learned optional chaining in react today. making: IPL project 🏏 issue faced: accessing nested objects like "object.object.object" fix/learned: optional chaining ("?.") to avoid crashes & undefined errors small thing, big sanity save. #reactjs #webdev #buildinpublic #javascript
To view or add a comment, sign in
-
-
If you think useEffect is just for API calls… you’re missing its real power. Let’s break it down 👇 🔹 useEffect runs AFTER render (commit phase) Types of Effects: No dependency → Runs on every render [] → Runs once (on mount) [dep] → Runs when dependency changes ⚠️ Common Mistake: Using useEffect for derived state Bad ❌ const [fullName, setFullName] = useState("") useEffect(() => { setFullName(firstName + lastName) }, [firstName, lastName]) Better ✅ const fullName = firstName + lastName 💡 Rule: “If you can calculate it during render → don’t use useEffect” 🔥 Senior Insight: useEffect is for SIDE EFFECTS only: API calls Subscriptions DOM manipulation #React #useEffect #FrontendEngineering #JavaScript #Coding
To view or add a comment, sign in
-
🧠 Day 18 of 21days challenge JavaScript WeakMap ⚡ WeakMap is a collection where keys must be objects. It helps in memory management because keys are weakly referenced. For easy understanding :- WeakMap = object keys only Garbage collected if no other references Useful to store private data 👉 That’s how memory leaks can be prevented This changed how I manage objects efficiently 🚀 #JavaScript #WeakMap #InterviewPrep #Frontend
To view or add a comment, sign in
-
-
🚀 💡 JavaScript Tricky Question Explanation const arr = [4, 10, 2, 8]; const result = arr.find(num => num > 5) + arr.findIndex(num => num > 5); console.log(result); 👉 Output: 11 👉 Explanation: * find() returns the first value > 5 → `10` * findIndex() returns its index → `1` * Final result → `10 + 1 = 11` ⚡ Both stop at the **first match** #JavaScript #WebDevelopment #Frontend #CodingInterview #JSConcepts
To view or add a comment, sign in
-
Why do we need the 𝘂𝘀𝗲𝗠𝗲𝗺𝗼 hook when we can perform heavy calculations inside 𝘂𝘀𝗲𝗦𝘁𝗮𝘁𝗲, which runs only once? The key difference is flexibility and reactivity. 𝘂𝘀𝗲𝗠𝗲𝗺𝗼 can run once or re-run when specific values change. It accepts two arguments: 1. A callback function 2. A dependency array You can pass values in the dependency array, and whenever any of those values change, React re-invokes the callback function. This ensures you always have the latest values inside the callback. Real-world use case: Validating edit form values on initial load and re-validating when certain conditions or inputs change. #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #ReactHooks #PerformanceOptimization #CodingTips
To view or add a comment, sign in
-
-
Scroll events giving you headaches? 😩 There's a better way. The Intersection Observer API lets you detect when elements enter the viewport — no scroll listeners, no layout thrashing, just clean and efficient JS. ⚡ I just published a full breakdown with real code examples, tips, and common mistakes to avoid. 🔧 Read it now 👉 hamidrazadev.com #javascript #webdev #frontend #learntocode #100daysofcode
To view or add a comment, sign in
-
-
Day 3 — useEffect ⚡ Why was useEffect even created? Things were working before it too! 🤔 Simple answer: →without it, your API fired on every render → infinite loops & duplicate requests. Use useEffect when: → Fetch data on mount → Subscribe & cleanup events → DOM manipulation → React to dependency changes What's your biggest useEffect mistake? 👇 #ReactJS #useEffect #JavaScript #30DaysOfReact #LearningInPublic
To view or add a comment, sign in
-
-
setTimeout does nothing inside the JavaScript engine. It's a label. A facade. When you call it, JS hands the work off to a browser feature - the actual timer lives outside JavaScript entirely. The browser runs it independently while JS continues on to the next line. All the features we think of as "JavaScript" - timers, network requests, DOM interactions - are actually browser APIs. JS just has labels that trigger them. This is how JS avoids blocking. It doesn't wait. It delegates. The result comes back later, through a controlled channel called the callback queue. Next: the event loop - the single mechanism that controls when deferred code is allowed back into JavaScript. #JavaScript #WebDevelopment #Programming #SoftwareEngineering
To view or add a comment, sign in
-
Development to Deployment: VS Code workflow made easy! Just a small thing built for fun while exploring tools. Logic Game: The Target Sum Challenge 🧩 Try the live tool here!👇 https://lnkd.in/dCuz7Uxa #GameDev #JavaScript #CodingFun #WebDevelopment #MentalMath #PuzzleGame #VSCode #LogicPuzzles #TechInnovation #Frontend
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