🤔 Why doesn’t React do Deep Comparison? At first I wondered… If two objects have the same values, why does React still think they are different? Example: const user1 = { name: "Alex" } const user2 = { name: "Alex" } console.log(user1 === user2) // false Both look identical… but React treats them as different. Why? 👇 Because React uses Shallow Comparison. Instead of checking every value inside an object, React only checks the reference. Now imagine if React did Deep Comparison. For every render it would have to check: user └ profile └ address └ city └ zip And this would happen across hundreds of components. That would make React very slow. ⚡ So React makes a smarter trade-off: • Compare primitive values directly • Compare object references instead of deep values This keeps React fast and scalable. That’s also why we update state like this: setUsers(prev => [...prev, newUser]) Sometimes React performance is not about writing complex code… It’s about understanding how React decides something changed. #React #ReactNative #FrontendDevelopment #SoftwareEngineering
React Shallow Comparison Explained
More Relevant Posts
-
Many developers use React every day… without really understanding what happens behind the scenes. Developers who started using React around 2013–2016 had to learn the component lifecycle, with class components, you had explicit methods like: - componentDidMount - componentDidUpdate - componentWillUnmount This made the three main phases very clear: Mounting → Updating → Unmounting Today, many developers start directly with hooks like useEffect. Hooks made React components easier to manage and more readable, but sometimes developers use useEffect without fully understanding what really happens behind the scenes. In reality, useEffect is just an abstraction over the same lifecycle concepts: - Logic after mounting - Logic after updates - Cleanup before unmounting The syntax changed, but the core idea of the React lifecycle never disappeared. Understanding these phases helps you write predictable, maintainable components and avoid common bugs related to rendering and side effects. Do you think developers should learn how React works under the hood, or is just using hooks enough? In my next post, I’ll dive into React Fiber. Once you understand Fiber, the way you think about rendering, scheduling, and performance will completely change.
To view or add a comment, sign in
-
-
I used to think React components were only for displaying data. But what happens when you need to fetch an API, start a timer, or change a page title? Today, I’m documenting how to handle these "Side Effects" using the useEffect hook. Think of it as a remote control for your component. It lets the UI "reach out" to external systems without blocking the main screen. Here is what I’m practicing to keep my apps synchronized: 1) The Dependency Array: This is the control center. I’m learning how an empty array [] makes the code run only once, while adding specific variables makes it run only when they change. 2) Pure Components: I'm focusing on keeping my components "pure"—data goes in, and UI comes out—while letting useEffect handle everything that happens "outside" that flow. 3) The Cleanup: I learned that if I start a timer or a subscription, I have to "turn off the lights" when the component is finished. Using the return pattern prevents memory leaks. I'm still learning the ropes, but mastering this hook is the key to building real-world, data-driven applications. Tomorrow, I’m tackling the "Prop Drilling" nightmare with the React Context API! Quick question: When you first started with React, did you find the dependency array confusing? It definitely took me a minute to get it right! #CodeWithWajid #ReactJS #WebDevelopment #30DaysOfCode #LearningToCode #BuildingInPublic #Frontend #useEffect
To view or add a comment, sign in
-
Most React performance issues I've seen come down to one thing: Components re-rendering when they don't need to. Here's what I see in codebases all the time: A parent component updates its state. Suddenly 6 child components re-render. None of them actually changed. But React doesn't know that unless you tell it. This is where useMemo and useCallback come in. useMemo — caches the result of a calculation. If the dependencies haven't changed, React skips the recalculation entirely and returns the cached value. Use it when you're computing something expensive — filtering a large list, transforming API data, building a derived object — and that computation runs on every render. useCallback — caches the function itself. Every time a component renders, functions get recreated in memory. If you're passing that function as a prop to a child component, the child sees a "new" function and re-renders unnecessarily. Use it when you're passing callbacks as props — especially to memoized child components. The rule I follow: → Is this value expensive to compute? → useMemo → Is this function being passed as a prop? → useCallback → Neither? Don't over-optimise — premature memoization adds complexity without benefit. I've used this consistently across SaaS products at Techoedge and it's one of the first things I look at when a frontend feels sluggish. What performance issues are you running into most in your React projects? Drop them below 👇 #ReactJS #Frontend #WebPerformance
To view or add a comment, sign in
-
Last quarter I spent 3 days profiling a React dashboard that felt broken. Users reported 400ms+ delays on every click. The team before me had already memo'd everything in sight. React.memo here, useMemo there. Like putting band-aids on a sinking ship. Turned out the actual problem was embarrassingly simple. One context provider. Twelve state slices shoved into it. A search field keystroke was re-rendering 80+ components because they all subscribed to the same god-context. The memos couldn't help — the parent was the problem. I split that provider into three domain-specific ones. Swapped derived-state recalculations for useSyncExternalStore. Threw react-window on the heaviest list instead of trying to optimize 200 individual row components. Added React.memo in exactly four places. Only where React DevTools Profiler showed actual wasted renders. Not "just in case." Four. Interaction latency went from 400ms to ~90ms. No new libraries. No rewrite. Honestly felt anticlimactic. The uncomfortable truth: most React perf work I've seen is teams reaching for micro-optimizations because it feels productive. But wrapping a child in memo won't save you if the parent re-renders on every state change. Profile first. Split contexts second. Memo last — and only where the profiler tells you to. 🔧 Curious — has anyone here had the opposite experience, where useMemo actually was the right first move? I've never seen it, but I want to be wrong. #ReactJS #FrontendDevelopment #PerformanceOptimization #WebDev #SeniorDeveloper
To view or add a comment, sign in
-
Stop overusing useEffect: 3 patterns for cleaner React code in 2026! While useEffect is one of the most powerful hooks in React, it’s also the most misused. Many developers use it to sync state, leading to unnecessary re-renders and "spaghetti code." In my recent projects, I’ve been focusing on writing more predictable components by following these 3 patterns: 1) You might not need an effect for data transformation If you can calculate something from existing props or state, do it during rendering. - Don't: Use an effect to update a filteredList state when items change. - Do: Use useMemo or just a plain variable during render. It’s faster and simpler. 2) Action handlers over effects If a state change is triggered by a specific user event (like a button click), put that logic in the event handler, not in a useEffect watching the state. It makes the data flow much easier to trace. 3) Lifting State Up vs. Context API Don’t jump straight to Context for everything. Start by lifting state up to the nearest common ancestor. Only move to Context or state management libraries when the prop-drilling actually hurts scalability. The goal? Leaner components, better performance, and easier debugging. What’s a React "bad habit" you’ve recently broken? Let’s share some clean code tips below👇 #ReactJS #TypeScript #WebDevelopment #SoftwareArchitecture #CleanCode #FrontendEngineering #TorontoTech #MERN
To view or add a comment, sign in
-
-
Day -3 of Road to Cracked 🚀 Today was less theory… more playing around 😄 Built a small theme switcher project using Context API — and finally saw a real use case instead of just concepts. Changing themes globally without passing props everywhere = feels powerful ⚡ After that, I moved to React Router… and things got interesting 👇 Discovered there are 3 ways to handle routing: Declarative → Using pre-built components (simple & common) Data → More structured, scalable approach (this one felt 🔥) Framework → Building your own routing system from scratch Reality check 🧠 In industry, mostly Declarative and Data modes are used. And one cool realization — 👉 Declarative routing internally uses the same concept of Context API. Everything in React is somehow connected… You just don’t see it at first. Slowly moving from “copy-paste developer” → “understanding developer” 🛠️ #ReactJS #ReactRouter #ContextAPI #LearningInPublic #RoadToCracked
To view or add a comment, sign in
-
-
The State of State Management in React (2026) 🧠 State management in React has gone through a full circle — from simple → complex → back to simple (but smarter). ⚡ Then vs Now We moved from prop drilling → heavy global stores → now… choosing the right tool for the right state. 🔥 What’s trending now Local state first (useState, useReducer) is back as the default Server state ≠ client state (huge mindset shift) Tools like TanStack Query dominate async/server state Lightweight stores like Zustand are replacing boilerplate-heavy solutions 📦 What about Redux? Redux isn’t dead — it’s just more intentional now. Used mainly for: Large-scale apps Complex shared state Strict architecture needs 🧩 Modern approach UI State → React (useState/useReducer) Server State → TanStack Query Global Client State → Zustand / Context 🚫 What’s fading Overusing Context for everything Writing unnecessary reducers & boilerplate Treating all state as global 🎯 Reality check There is no “one state management tool” anymore. Good developers don’t pick favorites — they pick fit. 💭 My take If your app feels complicated, your state strategy probably is. Simplify first. Add tools only when needed. #React #StateManagement #Frontend #JavaScript #WebDev
To view or add a comment, sign in
-
The DOM was a nightmare before React. Not because it was broken. Because the abstraction was wrong. You were working directly with the underlying layer instead of reasoning about what you actually wanted to build. React didn't fix the DOM. It gave you a way to think in terms of UI. The component model was so correct that it became obvious in retrospect. Every front-end framework followed suit or died. And it made two groups happy: the developers building components, and the people building tools on top of the primitives React provided. The back end has the same problem right now. Look at what a modern AI-driven system actually needs: an API framework, background job processing, a queue, a workflow engine, durable execution, shared state, streaming, observability, an agentic layer and observability tying it all together. That's 8 to 12 separate systems with their own domains, their own SDKs, and their own mental models. But underneath all of them, only three things are happening. A function does something. A worker processes something. A trigger starts it all. That's it. Everything else is configuration around those three primitives. The problem isn't that the tools are bad. The problem is that we're still operating directly on the DOM. We haven't found the component yet. When we do, the agent will use it automatically. Not because someone told it to. Because a smaller surface area is always the right choice.
To view or add a comment, sign in
-
-
Hey connections!! Here is an article about React Hooks: React Hooks: Simplifying State and Logic in Modern React React has evolved significantly over the years, and one of its most powerful additions is Hooks. Introduced in React 16.8, Hooks allow developers to use state and lifecycle features in functional components, eliminating the need for class components in most cases. What are React Hooks? React Hooks are built-in functions that let you “hook into” React features such as state management and lifecycle methods directly from functional components. Key React Hooks: useState: is used to manage state within a component. It allows developers to create and update variables that trigger re-rendering of the UI when changed. useEffect: is used to handle side effects such as API calls, subscriptions, or updating the DOM. It replaces lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount. useContext : allows components to access global data without passing props through multiple levels, reducing complexity. useRef : is used to directly access and interact with DOM elements or persist values across renders without causing re-renders. useMemo and useCallback are used for performance optimization by preventing unnecessary re-computations and re-renders. #snsInstitutions #designthinking #snsdesignthinkers
To view or add a comment, sign in
-
-
🚀 React JS vs Redux: DO’s & DON’Ts Every Frontend Dev Should Know Over the years, one thing I’ve learned building scalable apps with and — don’t overcomplicate state management. Here’s a quick breakdown 👇 ✅ DO’s • Use React for UI and component-level state • Use Redux for large, shared, complex state • Keep local state localized (forms, inputs, UI toggles) • Maintain a single source of truth in Redux • Write pure functions for reducers • Follow immutability principles • Structure code for predictable data flow ❌ DON’Ts • Don’t put every state into Redux • Don’t use Redux for small/simple apps • Avoid deep prop drilling (consider context or better structure) • Don’t write async logic directly in reducers • Don’t over-engineer with unnecessary Redux setup • Avoid boilerplate-heavy patterns when not needed • Don’t mix state management strategies randomly 💡 Pro Tip: Start simple with React. Introduce Redux only when your app complexity actually demands it. --- 🔥 What’s your go-to state management approach in 2026? Still Redux or moving to something lighter? #ReactJS #Redux #FrontendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #StateManagement #CleanCode #DeveloperTips #TechLeadership #FrontendEngineer
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