𝐀𝐛𝐨𝐫𝐭𝐂𝐨𝐧𝐭𝐫𝐨𝐥𝐥𝐞𝐫 𝐢𝐧 𝐑𝐞𝐚𝐜𝐭: 𝐀 𝐌𝐮𝐬𝐭-𝐊𝐧𝐨𝐰 : When we call an API in React (inside use-Effect), the request can sometimes take time. 𝐁𝐮𝐭 𝐰𝐡𝐚𝐭 𝐢𝐟 𝐭𝐡𝐞 𝐮𝐬𝐞𝐫: leaves the page, switches to another screen, or the component disappears. The API request may still be running in the background. 𝐓𝐡𝐢𝐬 𝐜𝐚𝐧 𝐜𝐚𝐮𝐬𝐞: bugs, unexpected UI behavior, wasted network calls 𝐓𝐡𝐚𝐭’𝐬 𝐰𝐡𝐞𝐫𝐞 𝐀𝐛𝐨𝐫𝐭𝐂𝐨𝐧𝐭𝐫𝐨𝐥𝐥𝐞𝐫 𝐡𝐞𝐥𝐩𝐬: 𝐖𝐡𝐲 𝐀𝐛𝐨𝐫𝐭𝐂𝐨𝐧𝐭𝐫𝐨𝐥𝐥𝐞𝐫 𝐢𝐬 𝐢𝐦𝐩𝐨𝐫𝐭𝐚𝐧𝐭,𝐖𝐡𝐞𝐧 𝐲𝐨𝐮 𝐜𝐚𝐧𝐜𝐞𝐥 𝐚 𝐫𝐞𝐪𝐮𝐞𝐬𝐭: 1). Prevents updating state after unmount 2). Avoids unnecessary network usage 3). Avoids race conditions (old request overriding new response) 𝐈𝐦𝐩𝐨𝐫𝐭𝐚𝐧𝐭 𝐍𝐨𝐭𝐞: Imagine your backend endpoint: /𝗮𝗽𝗶/𝘂𝘀𝗲𝗿𝘀 It takes 10 seconds to fetch users and process logic React calls the API But user closes the tab after 2 seconds 𝐘𝐨𝐮 𝐜𝐚𝐥𝐥 𝐀𝐛𝐨𝐫𝐭𝐂𝐨𝐧𝐭𝐫𝐨𝐥𝐥𝐞𝐫: React cancels the request immediately, No UI update will happen. But backend may still continue processing unless backend handles cancellation (client disconnect). 📌 In the next post, I’ll show how to handle aborted requests in Node/Express backend, detect when the client disconnects, and stop unnecessary processing. #ReactJS #JavaScript #Node #Express #Frontend #Backend #WebDevelopment #ReactHooks #CodingTips #AbortController
Prevent API Requests with AbortController in React
More Relevant Posts
-
Today while working on a React project, I had a small but useful realization. I was updating data based on a user’s selection, and my first instinct was to handle it with effects and state updates. Then it clicked 💡 The data wasn’t state. It was derived from state — which helped me properly understand useMemo. Out of curiosity, I mapped this back to Angular and realized the same mental model already exists there through pure pipes. Different frameworks, same principle: •Don’t store what you can derive •Separate side effects from render logic •Let the framework re-compute when inputs change Whether it’s React re-renders or Angular change detection, the goal is the same: Declarative, predictable UI. Have you had similar “aha” moments while switching frameworks? #React #Angular #Frontend
To view or add a comment, sign in
-
React Hooks didn’t just change syntax — they changed how we design UI systems. ⚙️🧠 Before hooks, stateful logic lived in class components, and “reuse” often meant HOCs, render props, and tangled lifecycles. Hooks made component logic composable again: small pieces of behavior you can share, test, and reason about. Why they matter in real projects 👇 ✅ Clearer mental model: state + effects are explicit. No hidden lifecycle edge cases. ✅ Reuse without wrappers: custom hooks turn messy cross-cutting concerns (auth, caching, analytics, feature flags) into clean APIs. ✅ Better performance control: useMemo/useCallback aren’t “speed buttons” — they’re tools to stabilize references for expensive computations and child renders. ✅ Fits modern frameworks: Next.js + React Server Components push more work to the server, but hooks still define predictable client boundaries (“use client”) and interactive behavior. Practical takeaway: treat useEffect as integration glue, not a default. If derived state can be computed during render, don’t store it. If an effect exists, ask: “what external system am I syncing with?” 🔌 What’s the hook pattern you rely on most in production? 👀 #react #javascript #nextjs #frontend #webdev #softwareengineering
To view or add a comment, sign in
-
-
React Hooks are special functions that allow functional components to use state, lifecycle features, context, refs, and performance optimizations without using class components. 1️⃣ State Hooks Purpose: Manage component data that changes over time. Hooks: useState, useReducer 2️⃣ Context Hooks Purpose: Access global/shared data without passing props manually through multiple levels. Hook: useContext 3️⃣ Ref Hooks Purpose: Access DOM elements or store mutable values without triggering re-rendering. Hooks: useRef, useImperativeHandle 4️⃣ Effect Hooks Purpose: Handle side effects such as API calls, subscriptions, timers, and DOM synchronization. Hooks: useEffect, useLayoutEffect, useInsertionEffect, useEffectEvent 5️⃣ Performance Hooks Purpose: Improve performance by preventing unnecessary re-renders and caching expensive calculations. Hooks: useMemo, useCallback, useTransition, useDeferredValue 6️⃣ Other Hooks Purpose: Provide specialized features such as debugging, unique IDs, managing action state, and subscribing to external stores. Hooks: useDebugValue, useId, useSyncExternalStore, useActionState 7️⃣ Custom Hooks Purpose: Reuse component logic across multiple components by creating developer-defined hooks (e.g., useAuth, useFetch). Understanding the purpose of each Hook category helps developers build scalable, maintainable, and high-performance React applications. #ReactJS #ReactHooks #FrontendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #Developers
To view or add a comment, sign in
-
-
🚫 Stop copy-pasting the same 𝘀𝘁𝗮𝘁𝗲 𝗺𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 𝗹𝗼𝗴𝗶𝗰 across your 𝗥𝗲𝗮𝗰𝘁 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀. ✅ Start extracting it into 𝗖𝘂𝘀𝘁𝗼𝗺 𝗥𝗲𝗮𝗰𝘁 𝗛𝗼𝗼𝗸𝘀. One of the biggest misconceptions junior React developers have is thinking components are only for 𝗨𝗜 𝗿𝗲𝘂𝘀𝗮𝗯𝗶𝗹𝗶𝘁𝘆. Yes, they reuse 𝗕𝘂𝘁𝘁𝗼𝗻𝘀 and 𝗜𝗻𝗽𝘂𝘁𝘀 well. But when it comes to business logic — fetching data, handling window events, or managing form state — they end up copy-pasting the same 𝘂𝘀𝗲𝗦𝘁𝗮𝘁𝗲 and 𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁 logic everywhere. 𝗧𝗵𝗲 𝗝𝘂𝗻𝗶𝗼𝗿 𝗪𝗮𝘆 👇 (𝗗𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝗱 𝗟𝗼𝗴𝗶𝗰) • The same 𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁 boilerplate is scattered across multiple React files. • Fixing a bug means updating logic in many places. • React components become bloated with non-UI responsibilities. 𝗧𝗵𝗲 𝗦𝗲𝗻𝗶𝗼𝗿 𝗪𝗮𝘆 👇 (𝗖𝘂𝘀𝘁𝗼𝗺 𝗛𝗼𝗼𝗸𝘀) • Reusable logic lives in 𝗰𝘂𝘀𝘁𝗼𝗺 𝗵𝗼𝗼𝗸𝘀 (e.g., 𝘂𝘀𝗲𝗙𝗲𝘁𝗰𝗵, 𝘂𝘀𝗲𝗪𝗶𝗻𝗱𝗼𝘄𝗦𝗶𝘇𝗲). • Components stay clean and focused on rendering UI. • Your app follows 𝗮 𝗦𝗶𝗻𝗴𝗹𝗲 𝗦𝗼𝘂𝗿𝗰𝗲 𝗼𝗳 𝗧𝗿𝘂𝘁𝗵 for shared behavior. 💡 𝗥𝘂𝗹𝗲 𝗼𝗳 𝘁𝗵𝘂𝗺𝗯: If you write the same 𝘂𝘀𝗲𝗘𝗳𝗳𝗲𝗰𝘁 or 𝘂𝘀𝗲𝗦𝘁𝗮𝘁𝗲 setup more than once, extract it into a custom React hook immediately. 𝗗𝗥𝗬 (𝗗𝗼𝗻’𝘁 𝗥𝗲𝗽𝗲𝗮𝘁 𝗬𝗼𝘂𝗿𝘀𝗲𝗹𝗳) applies to hooks too. #ReactJS #CustomHooks #FrontendDevelopment #JavaScript #CleanCode #SoftwareArchitecture #WebDevelopment #ReactDevelopers
To view or add a comment, sign in
-
-
React & JS #25 Why Context API becomes slow at scale:- React gives us many ways to centralize state… but performance and maintainability change drastically as apps grow. What works at small scale often breaks quietly later. :-) Why Context API becomes slow at scale Context updates re-render all consumers. That means: One state change → many components re-render Hard to control update boundaries Performance issues in frequently changing state Context is great for: Theme, auth, locale ❌ Not for high-frequency or complex state :-) Redux: Control & Predictability Redux centralizes state with explicit update flows. Pros Predictable state transitions Excellent debugging Scales well in large teams Cons Boilerplate More setup Easy to overuse for server state Best when control matters more than simplicity. :-) Zustand: Simplicity & Performance Zustand uses fine-grained subscriptions. Pros Minimal API Fewer re-renders No providers Easy mental model Cons Less opinionated Requires discipline at scale Best when simplicity and performance matter more than ceremony. TL;DR :- Context is for configuration. Redux is for complex, controlled state. Zustand is for lightweight, reactive state. Choosing the wrong tool works today… and becomes tomorrow’s performance bug. #ReactJS #JavaScript #StateManagement #ContextAPI #Redux #Zustand #FrontendArchitecture #WebDevelopment #FrontendEngineering
To view or add a comment, sign in
-
-
The difference between “working code” and “production-ready code” Code that works is only the first step. Production-ready code is about what happens next. Here’s how I see the difference 👇 Working code • solves the task for a happy path • works on a local machine • assumes ideal data and perfect users Production-ready code • handles errors, loading, and edge cases • considers performance and scalability • is readable and maintainable by others • survives real users, real data, and real pressure In production, code is read more often than it’s written. It’s changed, extended, and debugged under time constraints. That’s why I treat production readiness as a mindset: not “does it work?” but “can this live safely in the real world?” That question alone changes how you write frontend code. #frontend #frontenddeveloper #react #nextjs #javascript #webdevelopment #uidesign #performance #cleanCode #websites
To view or add a comment, sign in
-
-
#Frontend_in_2026: Fewer Footguns, Stronger Defaults Now that 2025 has ended and we’re starting with 2026, I’ve been reflecting on where the JavaScript ecosystem is headed. A pattern I’ve been noticing across the JavaScript ecosystem: the “frontend stack” is becoming more intentional about doing the right thing by default — less glue-code, fewer footguns, and more built-in clarity around performance, caching, and developer experience. React is a good example of this shift. Since React 19 went stable, the focus has moved from “how do I manage async UI without a mess?” to “how do I keep my UI predictable while it’s doing real work?” Features like Actions reduce boilerplate around common product workflows, and React Compiler 1.0 reinforces the idea that optimization should come from tooling, instead of sprinkling useMemo/useCallback everywhere as a lifestyle. The ecosystem around React is following the same direction. Create React App being officially sunset in early 2025 reinforced that production apps need stronger architectural defaults like routing/data-loading/caching patterns that “starter kits” don’t cover well long-term. Meanwhile, frameworks are treating architecture as a first‑class feature: Next.js 16 (Oct 2025) made caching more explicit with Cache Components and “use cache”. TypeScript continues to quietly anchor large frontend codebases, with recent releases and native tooling previews focusing on faster feedback loops and scalability — the kind of improvements that meaningfully affect how teams ship. All of this keeps reinforcing the same takeaway for me: the most valuable frontend skill set is still the fundamentals — strong JavaScript/TypeScript, clean React component boundaries, state management discipline, testing habits (unit + E2E), and performance awareness — and the ecosystem is increasingly rewarding people who build with those principles consistently. What’s one recent change (React/tooling/TypeScript) that genuinely made your day-to-day development smoother? #javascript #typescript #reactjs #frontend #webdevelopment #webperformance
To view or add a comment, sign in
-
Next.js 16 is a game-changer for full-stack development, and after diving deep into its new architecture, I'm convinced it's setting the standard for performance and developer productivity. As an engineer with 2+ years of experience across the stack (Next.js, React, Node.js, Nest.js, and various databases), I'm always looking for ways to build faster, more scalable applications. Next.js 16 delivers exactly that. The shift to Turbopack as the default bundler is huge, promising up to 5x faster production builds . This directly translates to faster CI/CD pipelines and a massive boost in developer iteration speed . Key highlights that stand out: - **Cache Components**: The new `use cache` directive gives us the granular, predictable caching control we've been asking for, which is critical for optimizing Core Web Vitals on content-heavy sites . - **React Compiler Integration**: This automates memoization, leading to cleaner code and preventing unnecessary re-renders without manual `useMemo` or `useCallback` hooks . - **Enhanced DX**: AI-assisted debugging and real-time route intelligence simplify identifying complex issues, making our lives easier . **Actionable Takeaway**: For your next project, leverage Partial Prerendering (PPR) with Cache Components. Serve a static shell instantly for a great LCP score, then stream in dynamic content. This hybrid approach is a powerful strategy for both performance and user experience . What Next.js 16 feature are you most excited to implement? #NextJS #WebDevelopment #FullStack #ReactJS #PerformanceOptimization #DeveloperExperience #SoftwareEngineering #JavaScript #NodeJS #Scalability
To view or add a comment, sign in
-
🚨 A small TypeScript mistake that silently breaks React I still see this in production React codebases: type Props = { setCount: (value: number) => void; }; Looks harmless, right? It’s not. This type removes a core React feature: functional state updates. React setters don’t just accept values — they also accept updater functions: setCount(10); // ✅ direct value setCount(prev => prev + 1); // ✅ functional update But if you type your setter as: (value: number) => void This will fail: setCount(prev => prev + 1); // ❌ Type error You’ve accidentally locked yourself out of one of React’s most important safety mechanisms. Why this matters Functional updates prevent stale state bugs: setCount(prev => prev + 1); setCount(prev => prev + 1); This guarantees correct updates when React batches state changes. Without it, subtle bugs creep in — especially in larger codebases. ✅ The correct way to type a setter Always use React’s built-in type: type Props = { setCount: React.Dispatch<React.SetStateAction<number>>; }; This preserves the full React API and keeps your code future-proof. It’s one line of types. But in a growing codebase, it’s the difference between: • Code that works • And code that works… until it doesn’t If you’re using React + TypeScript, don’t throw away part of the API. #TypeScript #React #Frontend #JavaScript #CodingTips
To view or add a comment, sign in
-
-
Is React alone enough in 2026? 🧐 The debate between a "Library" (React) and a "Framework" (Next.js) has reached a turning point. With the rise of Server Components and the absolute necessity of TypeScript, the way we build the frontend has changed forever. In my latest deep dive on Medium, I break down: ✅ When to choose Next.js over Vite/React. ✅ Why TypeScript is no longer "optional" for modern teams. ✅ The power of Concurrency and Server Actions. ✅ Advanced best practices for 2026. Stop building like it's 2020. Let's talk about the future of the stack. Read the full story here: #SoftwareEngineering #ReactJS #NextJS #TypeScript #WebDevelopment #FrontendArchitecture #TechTrends
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
👍