Why does React always ring twice? 🔔🔔 Day 73 of #100DaysOfCode - CogniChat Update 🚀 Today was supposed to be a pure "UI Polish" day. I spent hours perfecting the Glassmorphism look for the Login/Signup screens. I fixed the layout alignment for the First & Last Name inputs (making it actually industry-standard and responsive). It looks clean. It feels professional. Then, I tested the success message. The Bug (Watch the video): I click login once. The app notifies me twice. It’s the classic React "Double Render" ghost—likely React.StrictMode doing its job in development, or a zombie event listener I forgot to clean up. The Irony? 😅 The LeetCode problem I solved today was "Contains Duplicate." I solved the algorithm, but apparently, my frontend missed the memo. The universe definitely has a sense of humor. Current Status: 🎨 UI: Glassmorphism is 90% done. 🐛 Bug: Hunting down the double-fire issue. 🧠 DSA: Solved "Contains Duplicate" (Video coming soon). Links: 💻 Code: https://lnkd.in/gZqFDF9t 🚀 Live: https://lnkd.in/gJ5hSAYV 🧩 LeetCode: https://lnkd.in/gw-n6TnG React Devs: Is StrictMode the first thing you disable, or do you respect the double-render? 👇 #WebDevelopment #ReactJS #MERNStack #BugLife #UIUX #Glassmorphism #LeetCode #JuniorDeveloper #BuildInPublic
More Relevant Posts
-
⚡ Most React performance bugs aren’t caused by “slow code”. They’re caused by unnecessary re-renders. And most devs don’t even notice them. ━━━━━━━━━━━━━━━━━━━━━━━ The pattern I keep seeing: const Component = () => { const handleClick = () => { console.log("clicked"); }; return <Button onClick={handleClick} />; }; Looks innocent. Works perfectly. But here’s the hidden cost 👇 ━━━━━━━━━━━━━━━━━━━━━━━ What’s really happening: ❌ New function created on every render ❌ Child components re-render unnecessarily ❌ Memoization breaks silently ❌ Performance issues appear “randomly” ━━━━━━━━━━━━━━━━━━━━━━━ The optimized approach: const Component = () => { const handleClick = useCallback(() => { console.log("clicked"); }, []); return <Button onClick={handleClick} />; }; ✅ Stable references ✅ Predictable renders ✅ Works with React.memo ✅ Scales better in complex UIs ━━━━━━━━━━━━━━━━━━━━━━━ The real takeaway: This isn’t about using useCallback everywhere. It’s about: • Knowing how React compares props • Understanding reference equality • Optimizing when components grow Premature optimization is bad. Blind optimization is worse. ━━━━━━━━━━━━━━━━━━━━━━━ 💬 Honest question: Do you actively watch re-renders in your React apps or only care when users complain? Let’s discuss 👇 #ReactJS #JavaScript #FrontendPerformance #WebDevelopment #SoftwareEngineering #CleanCode #DeveloperCommunity
To view or add a comment, sign in
-
-
𝙏𝙝𝙚 𝙡𝙤𝙜𝙞𝙘 𝙗𝙚𝙝𝙞𝙣𝙙 𝙩𝙝𝙚 "𝙇𝙤𝙖𝙙𝙞𝙣𝙜" 𝙨𝙥𝙞𝙣𝙣𝙚𝙧. ⏳ In my last few posts, I talked about React state and the "invisible logic" of the frontend. But there is one thing that dictates our state more than anything else: 𝙋𝙧𝙤𝙢𝙞𝙨𝙚𝙨. In React, a Promise isn't just a JS concept—it’s the difference between a smooth UI and a broken one. I’ve realized that managing a Promise is really about managing three specific React states: ⏳ 𝙋𝙚𝙣𝙙𝙞𝙣𝙜 (𝙞𝙨𝙇𝙤𝙖𝙙𝙞𝙣𝙜): Keeping the user engaged while the data is in flight. ✅ 𝙁𝙪𝙡𝙛𝙞𝙡𝙡𝙚𝙙 (𝙙𝙖𝙩𝙖): Moving raw API responses into our component state. ❌ 𝙍𝙚𝙟𝙚𝙘𝙩𝙚𝙙 (𝙞𝙨𝙀𝙧𝙧𝙤𝙧): Gracefully handling the "Broken Promise" so the app doesn't crash. If we "promise" a user a feature but don't handle the rejection, we haven't built a UI—we’ve built a trap. My focus right now is moving away from "Happy Path" coding toward robust, predictable logic. Handling every .catch() as carefully as every .then(). How are you handling your "Broken Promises" in React today? Let’s connect! #ReactJS #JavaScript #WebDevelopment #FrontendEngineering #CleanCode #BCA #CodingLogic
To view or add a comment, sign in
-
Today I discovered a React behavior that completely changed how I think about 𝐮𝐬𝐞𝐄𝐟𝐟𝐞𝐜𝐭, 𝐜𝐥𝐨𝐬𝐮𝐫𝐞𝐬, 𝐚𝐧𝐝 𝐬𝐭𝐚𝐭𝐞 𝐮𝐩𝐝𝐚𝐭𝐞𝐬 Like many developers, I used to believe that when state updates, every async callback automatically gets the latest value. But this simple example proved me wrong: function App() { const [count, setCount] = useState(0); console.log("Render", count); useEffect(() => { setTimeout(() => { setCount(count + 1); setCount(count + 1); }, 1000); }, []); return null; } 👉 My expectation: count should become 2 👉 Reality: count becomes 1 Why? Because the setTimeout callback captures the initial state (0) — a concept known as 𝐬𝐭𝐚𝐥𝐞 𝐜𝐥𝐨𝐬𝐮𝐫𝐞. So React actually receives: setCount(1) setCount(1) And due to batching, both updates collapse into a single update. ✅ Final console output: Render 0 Render 1 💡 𝐁𝐢𝐠𝐠𝐞𝐬𝐭 𝐥𝐞𝐬𝐬𝐨𝐧: If your state update depends on previous state, never use the value directly inside async callbacks. Instead use functional updates: setCount(c => c + 1); setCount(c => c + 1); Now React uses the latest queued state and the result becomes 2. 𝐓𝐡𝐢𝐬 𝐬𝐦𝐚𝐥𝐥 𝐜𝐨𝐧𝐜𝐞𝐩𝐭 𝐞𝐱𝐩𝐥𝐚𝐢𝐧𝐬 𝐬𝐨 𝐦𝐚𝐧𝐲 𝐫𝐞𝐚𝐥-𝐰𝐨𝐫𝐥𝐝 𝐛𝐮𝐠𝐬: • 𝐢𝐧𝐭𝐞𝐫𝐯𝐚𝐥𝐬 𝐥𝐨𝐠𝐠𝐢𝐧𝐠 𝐨𝐥𝐝 𝐯𝐚𝐥𝐮𝐞𝐬 • 𝐰𝐞𝐛𝐬𝐨𝐜𝐤𝐞𝐭 𝐜𝐚𝐥𝐥𝐛𝐚𝐜𝐤𝐬 𝐮𝐬𝐢𝐧𝐠 𝐬𝐭𝐚𝐥𝐞 𝐬𝐭𝐚𝐭𝐞 • 𝐫𝐚𝐜𝐞 𝐜𝐨𝐧𝐝𝐢𝐭𝐢𝐨𝐧𝐬 𝐢𝐧 𝐚𝐬𝐲𝐧𝐜 𝐜𝐨𝐝𝐞 • 𝐮𝐧𝐞𝐱𝐩𝐞𝐜𝐭𝐞𝐝 𝐑𝐞𝐚𝐜𝐭 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐪𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 Sometimes the hardest React problems aren’t about syntax — they’re about mental models. Learning how React thinks is far more powerful than memorizing APIs. If you're preparing for React interviews, mastering render vs commit phase, closures, and batching is a huge advantage 🚀 #React #Frontend #JavaScript #WebDevelopment #ReactJS #LearningInPublic
To view or add a comment, sign in
-
💡Why Memoization Often Increases Complexity Debt on UI • Memoization is one of the first performance tools frontend developers reach for. useMemo, useCallback, and cached selectors. All promise fewer renders and faster UIs. But in many real-world React apps, memoization quietly adds complexity debt long before it adds measurable performance gains. • The first problem is fragile correctness. Memoization tightly couples performance to dependency accuracy. One missing dependency can introduce subtle bugs that don’t fail loudly; they fail silently. The UI looks correct, but by the time the bug appears, the cause is buried inside an optimization added months ago. • Second, memoization often targets the wrong bottleneck. Many frontend performance issues are caused by layout thrashing, large DOM trees, network delays, or main-thread contention, not re-renders. Memoizing a computation that takes microseconds doesn’t fix a frame drop caused by rendering or painting. 💫 At scale, this creates optimization sprawl: removing or refactoring code becomes risky, because performance behavior is now implicit rather than obvious. Approach isn’t “never memoize.” It’s optimize last, measure first, and simplify always. Clear code with predictable behavior scales better than clever optimizations whose benefits no one can confidently explain. #reactjs #memoization #frontend #javascript #programming #coding #javascript #nextjs #client #rendering
To view or add a comment, sign in
-
-
A few years ago I lost hours debugging what I was convinced was a React issue. State was behaving strangely. Something was mutating somewhere I was not touching. I checked reducers. I checked effects. I even questioned React’s rendering. 𝘐𝘵 𝘸𝘢𝘴 𝘯𝘰𝘵 𝘙𝘦𝘢𝘤𝘵. 𝗜𝘁 𝘄𝗮𝘀 𝗮 𝘀𝗵𝗮𝗹𝗹𝗼𝘄 𝗰𝗼𝗽𝘆. I had used the 𝘴𝘱𝘳𝘦𝘢𝘥 𝘰𝘱𝘦𝘳𝘢𝘵𝘰𝘳 thinking I cloned the object. Technically I did. But only the first layer. One nested object was still pointing to the same reference. So when another part of the app updated it, my “new” state changed too. That was the moment shallow vs deep copy stopped being a theory and became very practical. 𝗦𝗵𝗮𝗹𝗹𝗼𝘄 𝗰𝗼𝗽𝘆 𝗴𝗶𝘃𝗲𝘀 𝘆𝗼𝘂 𝗮 𝗻𝗲𝘄 𝗼𝘂𝘁𝗲𝗿 𝗼𝗯𝗷𝗲𝗰𝘁. 𝗗𝗲𝗲𝗽 𝗰𝗼𝗽𝘆 𝗴𝗶𝘃𝗲𝘀 𝘆𝗼𝘂 𝗶𝗻𝗱𝗲𝗽𝗲𝗻𝗱𝗲𝗻𝗰𝗲. In small projects, this rarely hurts. In larger systems, this is where subtle bugs begin. Over time I have learned to ask one simple question before cloning: - Do I want shared behavior or true isolation? That one question has saved me more debugging hours than any library ever has. How do you usually approach cloning in production React apps? #JavaScript #FrontendDevelopment #ReactJS #SoftwareEngineering #CleanCode #SeniorDeveloper
To view or add a comment, sign in
-
-
useMemo. useCallback. React.memo. Developers treat these as features. They're not. They're workarounds. Every state change in React triggers a full component re-render. The entire function re-executes. A new Virtual DOM tree is produced. A diffing algorithm compares old vs new. Patches are computed and applied. You're paying the cost of diffing an entire tree just to update a single text node. Memoization can prune branches, but it introduces its own overhead - dependency comparison, cognitive complexity, and it's entirely opt-in. You have to manually identify what to memoize. Miss one spot and your "optimized" app is back to re-rendering everything. What if the framework just... didn't re-render? In Granular, components execute once. When a reactive value changes, only the specific DOM node bound to that value updates. Nothing else runs. Nothing else is compared. No memoization needed. No optimization hooks. No mental model of "which renders can I skip." Full explanation: https://lnkd.in/dtQqp9YW #javascript #frontend #react #webdev #performance
To view or add a comment, sign in
-
🚀 5 React Concepts That Transformed My Development Workflow After spending countless hours building with React, I've discovered that the real power isn't in the syntax—it's in understanding the "why" behind the patterns. Here are 5 game-changing concepts every React developer should know: 🔁 1. The Closure Trap in Hooks useEffect and useState rely on closures. If you're not careful with dependency arrays, you'll be debugging stale values for hours. Understanding JavaScript closures = mastering React hooks. 🎭 2. Render Props Pattern Before hooks, this was the king of sharing logic. Still incredibly useful when you need to share code between components with flexible rendering needs. It's like passing JSX as a function—pure genius. 🧩 3. Error Boundaries One error shouldn't crash your entire app. Error boundaries let you fail gracefully, showing fallback UI while keeping the rest of your application functional. Your users will thank you. ⚡ 4. Memoization Strategies React.memo, useMemo, useCallback—they're not just performance tools. They're about preventing unnecessary re-renders and optimizing expensive calculations. Use them wisely, or don't use them at all. 🔄 5. The Power of useRef Beyond DOM References useRef persists values across renders without triggering re-renders. Perfect for tracking previous values, storing interval IDs, or keeping mutable data that shouldn't cause updates. 🎯 Bonus: Component Lifecycle in the Hooks Era useEffect combined with useRef can replicate componentDidMount, componentDidUpdate, and componentWillUnmount with cleaner, more readable code. React isn't just about building UIs—it's about building UIs that scale, perform, and make developers happy. 🌟 What's one React concept that clicked for you late in your journey? Share below! 👇 #ReactJS #WebDevelopment #FrontendEngineering #JavaScript #CodingTips #ReactHooks #SoftwareEngineering #TechCommunity #DeveloperProductivity #WebDevLife
To view or add a comment, sign in
-
⚛️ React Day 9 – Understanding useReducer Hook 🚀 Today, I learned how to manage complex state logic in React using the useReducer hook. 🔹 What is useReducer? useReducer is an alternative to useState that is better suited for handling complex state transitions. It works by using a reducer function that decides how the state should change based on dispatched actions. 💡 What I learned: • How state and actions work together • How to define a reducer function • How to dispatch actions to update state • Why useReducer is useful for complex UI logic • How it relates to Redux concepts In simple words: 👉 useReducer = state management using actions and a central update function. Understanding useReducer helped me see how scalable React applications structure their state updates more predictably. Still learning and building step by step ⚛️🚀 #React #ReactJS #useReducer #StateManagement #FrontendDevelopment #LearningJourney #WebDevelopment #JavaScript
To view or add a comment, sign in
-
-
🚀 Day 1 of sharing daily dev learnings Today’s topic: React Performance ⚡ Problem: My page was re-rendering too many times. Even small state changes were slowing the UI. Mistake: I was recalculating heavy data on every render. Fix: Used useMemo to memoize derived values. Example: const filtered = useMemo(() => { return users.filter(u => u.active) }, [users]) Result: ✅ Faster renders ✅ Smoother UI ✅ Cleaner logic Lesson: Don’t optimize everything. Optimize expensive computations only. Small React improvements like this make a BIG difference in production apps. What’s one React optimization you use often? 👇 #ReactJS #Frontend #WebDevelopment #JavaScript #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