Everything inside your component is recreated on every render. Most developers know this. But very few actually feel the impact of it. I didn’t… until it started affecting performance in a real feature. When React re-renders a component, it doesn’t “update” it. It runs the entire function again. That means: • Variables are re-created • Functions get new references • Objects & arrays become new instances Even if the UI looks exactly the same. At first, this feels harmless. Until you see something like this 👇 A small state change in parent → Triggers multiple child re-renders → No visible bug → but UI becomes slower The problem wasn’t React. It was this: const data = { value: count }; const handleClick = () => doSomething(); Looks fine. But on every render: - data is a new object - handleClick is a new function And React sees: “New reference = something changed” The real issue is not re-rendering. It’s uncontrolled identity changes. That’s when these stopped being “optimizations” for me: • React.memo • useCallback • useMemo And became tools to control behavior. The shift that matters: Don’t ask: Why did it re-render? Ask: What changed by reference? Once you understand this, you stop writing React casually. And start writing it intentionally. Curious — what’s one time React rendering surprised you? #ReactJS #Frontend #JavaScript #WebDevelopment #SoftwareEngineering #DevLife
React Rendering Gotcha: Uncontrolled Identity Changes
More Relevant Posts
-
Why does your 'ref' return 'null' the moment you wrap your input in a custom component? It is one of those React quirks that trips up even experienced developers. By default, refs do not behave like props. They are treated as special instances that stop at the component boundary to protect encapsulation. This is exactly why we need 'forwardRef'. It acts as a bridge that allows a parent component to reach through a child and grab a direct handle on an internal DOM node. The most practical application is building a reusable UI library. If you create a custom 'Input' or 'Button' component, your parent component might need to call '.focus()' or '.scrollIntoView()'. Without 'forwardRef', your parent is just holding a reference to a React internal object, not the actual HTML element. Another real-world scenario involves Higher-Order Components (HOCs). If you wrap a component with a 'withAnalytics' or 'withTheme' wrapper, that wrapper will 'swallow' the ref by default. By using 'forwardRef' in your HOC implementation, you ensure the reference passes through the wrapper and lands on the component that actually needs it. It is about making your abstractions transparent and ensuring that the parent component maintains the control it expects over the physical DOM. Using this pattern sparingly is key. It is an escape hatch for those moments where declarative state isn't enough to manage physical browser behavior. It keeps your component interfaces clean while providing the necessary access for specialized UI interactions. #ReactJS #SoftwareEngineering #Frontend #WebDevelopment #Javascript #CodingTips #CodingBestPractices
To view or add a comment, sign in
-
🚀 Understanding useRef in React — Simplified! Not all data in React should trigger a re-render. 👉 That’s where useRef becomes powerful. 💡 What is useRef? useRef is a hook that lets you store a mutable value that persists across renders—without causing re-renders. ⚙️ Basic Syntax const ref = useRef(initialValue); 👉 Access value using: ref.current 🧠 How it works Value persists across renders Updating it does NOT trigger re-render Works like a mutable container 🔹 Example const countRef = useRef(0); const handleClick = () => { countRef.current += 1; console.log(countRef.current); }; 👉 UI won’t update—but value persists 🧩 Real-world use cases ✔ Accessing DOM elements (focus, scroll) ✔ Storing previous values ✔ Managing timers / intervals ✔ Avoiding unnecessary re-renders 🔥 Best Practices (Most developers miss this!) ✅ Use useRef for non-UI data ✅ Use it for DOM access ✅ Combine with useEffect when needed ❌ Don’t use useRef for UI state ❌ Don’t expect UI updates from it ⚠️ Common Mistake // ❌ Expecting UI update countRef.current += 1; 👉 React won’t re-render 💬 Pro Insight 👉 useRef = Persist value without re-render 👉 useState = Persist value with re-render 📌 Save this post & follow for more deep frontend insights! 📅 Day 14/100 #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #useRef #WebDevelopment #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Most React performance problems don’t come from re-renders. They come from creating new identities every render. This is something I completely overlooked for years. --- Example 👇 const options = { headers: { Authorization: token } }; useEffect(() => { fetchData(options); }, [options]); Looks harmless. But this runs on every render. Why? Because "options" is a new object every time → new reference → dependency changes → effect runs again. --- Now imagine this in a real app: - API calls firing multiple times - WebSocket reconnecting randomly - Expensive logic running again and again All because of reference inequality, not value change. --- The fix is simple, but rarely discussed 👇 const options = useMemo(() => ({ headers: { Authorization: token } }), [token]); Now the reference is stable. The effect runs only when it should. --- This doesn’t just apply to objects: - Functions → recreated every render - Arrays → new reference every time - Inline props → can break memoization --- The deeper lesson: React doesn’t compare values. It compares references. --- Since I understood this, my debugging approach changed completely. Whenever something runs “unexpectedly”, I ask: 👉 “Did the reference change?” --- This is one of those small concepts… that silently causes big production issues. --- Curious — have you ever debugged something like this? #ReactJS #Frontend #JavaScript #WebDevelopment #Performance
To view or add a comment, sign in
-
𝐇𝐨𝐰 𝐈 𝐑𝐞𝐝𝐮𝐜𝐞𝐝 𝐑𝐞𝐚𝐜𝐭 𝐑𝐞𝐧𝐝𝐞𝐫 𝐓𝐢𝐦𝐞 𝐛𝐲 𝟔𝟎% 🚀 Recently, I worked on a React dashboard application where the UI felt slow and unresponsive 😓 Pages were taking too long to update especially with large data sets So I decided to debug the issue 👇 🔍 Step 1 — Measured performance Used React DevTools Profiler Found multiple unnecessary re-renders ⚠️ Problem Every state change was re-rendering large components unnecessarily Fixes I applied 👇 ⚡ Used React.memo Prevented child components from re-rendering when props didn’t change 🧠 Applied useMemo Memoized expensive calculations to avoid recalculating on every render 🔁 Used useCallback Stopped functions from being recreated on every render 📦 Improved component structure Split large components into smaller ones Moved state closer to where it was needed 🔑 Fixed key usage in lists Replaced index keys with unique IDs 🚀 Result ✔ ~60% reduction in render time ✔ Smooth UI interactions ✔ Better user experience Key learning 💡 Performance issues are often not obvious They hide in unnecessary re-renders Tip for developers ⚠️ Don’t optimize blindly Measure → Identify → Fix Good developers make things work. Great developers make them fast. #ReactJS #FrontendDeveloper #WebDevelopment #JavaScript #Performance #ReactOptimization #SoftwareDeveloper #CodingInterview
To view or add a comment, sign in
-
🚀 useDeferredValue in React — Smooth UI Without Blocking Ever noticed this? 👉 Typing feels laggy when filtering large data 👉 UI freezes during heavy updates You fixed it with useTransition… Now meet its smarter sibling 👉 useDeferredValue 💡 What is useDeferredValue? useDeferredValue lets you: 👉 Delay updating a value 👉 Keep UI responsive 👉 Let React handle prioritization ⚙️ Basic Syntax const deferredValue = useDeferredValue(value); 👉 React delays updating this value 👉 Until higher priority work is done 🧠 How it works const [query, setQuery] = useState(""); const deferredQuery = useDeferredValue(query); const filteredData = useMemo(() => { return expensiveFilter(data, deferredQuery); }, [deferredQuery]); 👉 Typing stays fast 👉 Filtering happens in background 🧩 Real-world Example Search input: ❌ Without useDeferredValue: Every keystroke triggers heavy filtering UI becomes slow ✅ With useDeferredValue: Input stays smooth Results update slightly later 🔥 Key Difference vs useTransition 👉 useTransition → delays state update 👉 useDeferredValue → delays value usage ⚠️ Common Mistake // ❌ Using for simple values const value = useDeferredValue(count); 👉 Not needed for cheap operations 🔥 Best Practices ✅ Use with expensive computations ✅ Combine with useMemo ✅ Ideal for search/filter UI ❌ Don’t use everywhere blindly 💬 Pro Insight (Senior-Level Thinking) 👉 useDeferredValue improves: ✔ Perceived performance ✔ User experience 👉 Not actual speed—but responsiveness 📌 Save this post & follow for more deep frontend insights! 📅 Day 26/100 #ReactJS #FrontendDevelopment #JavaScript #ReactHooks #ConcurrentRendering #PerformanceOptimization #SoftwareEngineering #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Hi! I’ve just published a new article in my 𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗦𝗰𝗮𝗹𝗮𝗯𝗹𝗲 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸𝘀 series: 𝗣𝗮𝗿𝘁 𝟱 — 𝗥𝗲𝗻𝗱𝗲𝗿𝗶𝗻𝗴 𝗘𝗻𝗴𝗶𝗻𝗲𝘀: 𝗨𝗽𝗱𝗮𝘁𝗶𝗻𝗴 𝘁𝗵𝗲 𝗨𝗜 𝗘𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝘁𝗹𝘆 This article explores a practical but very important question: When state changes, how does a framework decide what should actually change in the DOM? That is where rendering engines become essential. They are the part of the system responsible for deciding: • 𝘄𝗵𝗮𝘁 𝗻𝗲𝗲𝗱𝘀 𝘁𝗼 𝘂𝗽𝗱𝗮𝘁𝗲 • 𝘄𝗵𝗮𝘁 𝗰𝗮𝗻 𝘀𝘁𝗮𝘆 𝘂𝗻𝘁𝗼𝘂𝗰𝗵𝗲𝗱 • 𝗵𝗼𝘄 𝘁𝗼 𝗮𝘃𝗼𝗶𝗱 𝘂𝗻𝗻𝗲𝗰𝗲𝘀𝘀𝗮𝗿𝘆 𝗗𝗢𝗠 𝘄𝗼𝗿𝗸 • 𝗵𝗼𝘄 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝘀𝗰𝗮𝗹𝗲𝘀 𝗮𝘀 𝘁𝗵𝗲 𝗨𝗜 𝗴𝗿𝗼𝘄𝘀 This is also where frameworks start to diverge in a meaningful way. Some rely on rerendering and diffing. Others track dependencies more precisely. Others move more work into compilation. Different approach. Same core problem: how to keep the UI fast without turning the architecture into chaos. Once you understand the rendering engine, frameworks stop feeling like magic. You start seeing the trade-offs behind React, Vue, Lit, Solid, and others much more clearly. 👉 article link in the comments 𝗦𝗲𝗿𝗶𝗲𝘀 𝗿𝗼𝗮𝗱𝗺𝗮𝗽 • Part 1 — Building Scalable JavaScript Frameworks • Part 2 — Why JavaScript Frameworks Exist • Part 3 — Anatomy of a Modern JavaScript Framework • Part 4 — From Templates to DOM: Parsing and Compilation • 𝗣𝗮𝗿𝘁 𝟱 — 𝗥𝗲𝗻𝗱𝗲𝗿𝗶𝗻𝗴 𝗘𝗻𝗴𝗶𝗻𝗲𝘀: 𝗨𝗽𝗱𝗮𝘁𝗶𝗻𝗴 𝘁𝗵𝗲 𝗨𝗜 𝗘𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝘁𝗹𝘆 (this one) • Part 6 — Reactive Systems and Data Flow • Part 7 — Designing Component Architectures • Part 8 — Routing and Application Structure • Part 9 — Performance Strategies for Large Applications • Part 10 — The Future of Frontend Frameworks #frontend #javascript #architecture #webdevelopment #innovation
To view or add a comment, sign in
-
-
🚀 Stop Dumping Everything in /src: The Blueprint for Production-Ready Frontend We've all been there: a project starts small, and suddenly your src folder is a graveyard of 50+ files with no clear home. The secret to a maintainable codebase isn't just the code you write-it's where you put it. A standardized folder structure like the one in this image is a gift to your future self (and your teammates). Why this specific setup works: 📂 api & services: Separation of concerns. Your api folder handles the raw Axios/Fetch calls, while services handles the logic of how that data is transformed for your Ul. 📂 components (ui vs. layout): Distinguishing between atomic Ul elements (buttons, inputs) and structural layouts (navbars, footers) makes finding components 10x faster. 📂 hooks & utils: If logic is used more than once, extract it. Custom hooks keep your components lean and focused on the view. 📂 context & redux: Clear boundaries for state management. Use context for global themes/auth and redux (or Zustand) for complex, data-heavy state. The "Scale" Test: Ask yourself: "If a new developer joined the team today, could they find the login API call in under 10 seconds?" If the answer is no, it might be time for a refactor. The Bottom Line: You don't build a house without a blueprint. Don't build an enterprise app without a structured directory. What does your "gold standard" frontend folder structure look like? Do you prefer "feature-based" folders or "type-based" ones? Let's debate in the comments! 👇 #webdevelopment #ReactJS #FrontendDevelooment #API #FullstackDevelopment
To view or add a comment, sign in
-
-
⚛️ 𝗔𝘃𝗼𝗶𝗱𝗶𝗻𝗴 𝗢𝘃𝗲𝗿-𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗲𝗱 𝗦𝘁𝗮𝘁𝗲 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 In many React applications, state management becomes more complex than it actually needs to be. 𝗔 𝗰𝗼𝗺𝗺𝗼𝗻 𝗽𝗮𝘁𝘁𝗲𝗿𝗻: • adding Redux / global state too early • moving all state to global store • increasing boilerplate and complexity But not all state needs to be global. ❌ 𝗢𝘃𝗲𝗿-𝗲𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗲𝗱 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 // 𝘨𝘭𝘰𝘣𝘢𝘭 𝘴𝘵𝘰𝘳𝘦 𝘧𝘰𝘳 𝘦𝘷𝘦𝘳𝘺𝘵𝘩𝘪𝘯𝘨 𝘤𝘰𝘯𝘴𝘵 𝘶𝘴𝘦𝘳 = 𝘶𝘴𝘦𝘚𝘦𝘭𝘦𝘤𝘵𝘰𝘳(𝘴𝘵𝘢𝘵𝘦 => 𝘴𝘵𝘢𝘵𝘦.𝘶𝘴𝘦𝘳); 𝘤𝘰𝘯𝘴𝘵 𝘵𝘩𝘦𝘮𝘦 = 𝘶𝘴𝘦𝘚𝘦𝘭𝘦𝘤𝘵𝘰𝘳(𝘴𝘵𝘢𝘵𝘦 => 𝘴𝘵𝘢𝘵𝘦.𝘵𝘩𝘦𝘮𝘦); 𝘤𝘰𝘯𝘴𝘵 𝘮𝘰𝘥𝘢𝘭 = 𝘶𝘴𝘦𝘚𝘦𝘭𝘦𝘤𝘵𝘰𝘳(𝘴𝘵𝘢𝘵𝘦 => 𝘴𝘵𝘢𝘵𝘦.𝘮𝘰𝘥𝘢𝘭); Even simple UI states are stored globally. This makes: • debugging harder • components tightly coupled • unnecessary re-renders ✅ Practical approach Use state based on scope: • local state → useState • shared state → Context API • server state → React Query • global app state → only when truly needed 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: 𝘧𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘔𝘰𝘥𝘢𝘭() { 𝘤𝘰𝘯𝘴𝘵 [𝘪𝘴𝘖𝘱𝘦𝘯, 𝘴𝘦𝘵𝘐𝘴𝘖𝘱𝘦𝘯] = 𝘶𝘴𝘦𝘚𝘵𝘢𝘵𝘦(𝘧𝘢𝘭𝘴𝘦); 𝘳𝘦𝘵𝘶𝘳𝘯 ( <> <𝘣𝘶𝘵𝘵𝘰𝘯 𝘰𝘯𝘊𝘭𝘪𝘤𝘬={() => 𝘴𝘦𝘵𝘐𝘴𝘖𝘱𝘦𝘯(𝘵𝘳𝘶𝘦)}>𝘖𝘱𝘦𝘯</𝘣𝘶𝘵𝘵𝘰𝘯> {𝘪𝘴𝘖𝘱𝘦𝘯 && <𝘥𝘪𝘷>𝘔𝘰𝘥𝘢𝘭 𝘊𝘰𝘯𝘵𝘦𝘯𝘵</𝘥𝘪𝘷>} </> ); } 📌 𝗣𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻 𝗺𝗶𝗻𝗱𝘀𝗲𝘁: • keep state as close as possible to where it’s used • avoid global store for UI state • introduce tools only when required • prefer simplicity over abstraction 📌 𝗪𝗵𝘆 𝘁𝗵𝗶𝘀 𝗺𝗮𝘁𝘁𝗲𝗿𝘀: • cleaner architecture • better performance • easier debugging • more maintainable code Not every problem needs a global state solution. Sometimes, simple patterns scale better. 💬 Curious — Do you decide state location upfront, or refactor as the app grows? #ReactJS #StateManagement #FrontendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #CleanCode #ReactArchitecture
To view or add a comment, sign in
-
📘 How React Re-renders Work (and How to Avoid Unnecessary Re-renders) 🔹 What is a Re-render? A re-render happens when React updates a component and reflects changes in the UI. This usually occurs when: ✔ State changes (useState) ✔ Props change ✔ Parent component re-renders 🔹Example const [count, setCount] = useState(0); <button onClick={() => setCount(count + 1)}> Click Me </button> 👉 Every time count updates → component re-renders 🔹 Important When a component re-renders: 👉 All its child components also re-render (by default) Even if their data hasn’t changed ⚠️ 🔹 Real Problem Unnecessary re-renders can: ❌ Slow down performance ❌ Cause lag in large applications ❌ Trigger unwanted API calls 🔹 How to Avoid Unnecessary Re-renders ✅ 1. Use React.memo export default React.memo(MyComponent); Prevents re-render if props haven’t changed. ✅ 2. Use useCallback for functions const handleClick = useCallback(() => { doSomething(); }, []); Prevents function recreation on every render. ✅ 3. Use useMemo for expensive calculations const result = useMemo(() => computeValue(data), [data]); Avoids recalculating values unnecessarily. ✅ 4. Keep State Minimal Only store what is necessary. Too much state = more re-renders. 🔹 Real-World Insight In large apps (dashboards, tables, filters): 👉 Poor render optimization can impact user experience heavily. Small optimizations here make a big difference. 👉 Re-renders are not bad—but unnecessary re-renders are. #ReactJS #FrontendDevelopment #Performance #JavaScript #WebDevelopment
To view or add a comment, sign in
-
-
Hook: We need to talk about the awkward phase between useState and installing Redux. For a long time, I defaulted to useState for literally everything. Then you hit a feature—like a complex multi-step form or a data-heavy dashboard—and suddenly your component has six different state setters. Your event handlers turn into a tangled mess of setLoading(false), setData(res), and setError(null), all firing at once and risking race conditions. That’s exactly when useReducer goes from being "that confusing React hook" to the most vital tool for clean architecture. ✅ When you SHOULD use it: Dependent State: When updating one piece of state requires changing another at the exact same time (e.g., resolving an API call updates loading, data, and error simultaneously). Complex Objects: When your state is a deeply nested object or array that requires precise mapping or filtering on every update. Centralizing Logic: When you want to pull messy update logic out of your UI component and into a pure, highly testable JavaScript function. You can unit-test a reducer without ever touching a React component. ❌ When you SHOULD NOT use it: Simple Primitives: Please don't write a 15-line reducer with action types and switch statements just to toggle a modal open and closed. useState is perfectly fine for isolated, flat values. Just to look "advanced": The boilerplate is real. If the state is simple, keep the code simple. Don't frustrate the next developer who reads your code just to flex a hook. 💡 Why it matters in production: At the product-company level, you don't always need Redux, Zustand, or MobX for every feature. Pairing useReducer with the Context API gives you a powerful, localized global state. You can pass the dispatch function down the tree, completely avoiding prop-drilling without bloating your bundle size with third-party dependencies. It takes a minute to shift your brain from "updating values" to "dispatching actions," but your future self (and your teammates) will thank you when debugging. What is your personal threshold for making the switch from useState to useReducer? Let's debate below. #ReactJS #FrontendEngineering #SoftwareArchitecture #CleanCode #JavaScript
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