🚨 Most React developers misuse "useEffect" And it’s slowing down their apps. Here’s the mistake 👇 useEffect(() => { fetch("/api/products") }, []) Looks correct, right? But this pattern becomes a problem in real applications. Why? Because developers start putting everything inside useEffect: ❌ API calls ❌ data transformations ❌ business logic ❌ state syncing Result: • messy components • hard-to-debug code • unnecessary re-renders 💡 Better approach: 👉 Move logic OUT of components 👉 Create a service layer 👉 Use proper data fetching tools (React Query, etc.) Example: const { data } = useQuery("products", fetchProducts) Now your component becomes: ✔ cleaner ✔ easier to maintain ✔ more scalable 💡 "useEffect" is not for everything. It’s only for side effects that truly belong to the component. #reactjs #frontend #javascript #softwareengineering #webdevelopment
React useEffect misuse slows apps, move logic to service layer
More Relevant Posts
-
Most React developers are still thinking in a client-first way — and that’s becoming a problem. Server-first React is quietly changing how we build applications. The traditional approach: - Fetch in useEffect - Move data through APIs (JSON) - Render on the client This is no longer the default in modern React + Next.js. What’s changing: - Server Components handle data and rendering - Client Components are used only for interactivity - UI can be streamed directly from the server - Hydration is selective, not global Impact: - Less JavaScript sent to the browser - Reduced reliance on client-side state - Better performance by default - Simpler data flow (often without an extra API layer) A useful mental model: Server = data + structure Client = interaction This isn’t just a feature update - it’s a shift in architecture. If you’re still using useEffect primarily for data fetching, it may be time to rethink how your React apps are structured. #React #Frontend #Fullstack #JavaScript #WebDevelopment
To view or add a comment, sign in
-
-
Day 21: useMemo vs useCallback (Most Confusing React Topic) Many React developers get confused between useMemo and useCallback. But the difference is actually simple 📌 What is useMemo? useMemo is used to memoize a computed value. 👉 It prevents expensive calculations from running again and again. import { useMemo, useState } from "react"; function App() { const [count, setCount] = useState(0); const expensiveValue = useMemo(() => { console.log("Calculating..."); return count * 10; }, [count]); return ( <div> <h1>{expensiveValue}</h1> <button onClick={() => setCount(count + 1)}>Increase</button> </div> ); } ✅ It stores the result/value. 📌 What is useCallback? useCallback is used to memoize a function. 👉 It prevents a function from being recreated on every render. import { useCallback, useState } from "react"; function App() { const [count, setCount] = useState(0); const handleClick = useCallback(() => { console.log("Clicked"); }, []); return ( <div> <button onClick={handleClick}>Click</button> <h1>{count}</h1> <button onClick={() => setCount(count + 1)}>Increase</button> </div> ); } ✅ It stores the function reference. 🔥 Simple Difference ✅ useMemo → returns a VALUE ✅ useCallback → returns a FUNCTION 📌 When to use them? useMemo ✔ Heavy calculations ✔ Derived data useCallback ✔ Passing functions as props ✔ React.memo optimized components 🎯 Interview Line 👉 useMemo memoizes values, useCallback memoizes functions. #ReactJS #useMemo #useCallback #FrontendDevelopment #JavaScript #WebDevelopment #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
🚨 Infinite API Calls: The Silent Killer of Your App Everything looks fine… until your API starts getting hammered with requests nonstop 😬 If you’ve worked with React (or any frontend framework), chances are you’ve faced this at least once. 🔴 The Problem: Your component keeps calling an API again… and again… and again. ➡️ Backend gets overloaded ➡️ UI becomes sluggish ➡️ Rate limits get hit ➡️ Users suffer Most of the time, it comes down to a simple mistake. ⚠️ Common Causes: Missing dependency array in useEffect: Runs on every render Incorrect dependencies: State updates trigger the effect repeatedly Updating state inside the same effect that depends on it: Creates a loop Functions recreated on every render: Triggers effect again ⚡ How to fix it: ✅ 1. Use Dependency Array Correctly useEffect(() => { fetchData(); }, []); // runs only once ✅ 2. Be Careful with State Updates Avoid updating a state that is also in your dependency array unless necessary. ✅ 3. Memoize Functions const fetchData = useCallback(() => { // API call }, []); ✅ 4. Use Flags / Conditions if (!data) { fetchData(); } ✅ 5. Use Libraries Tools like React Query or SWR handle caching, refetching, and prevent unnecessary calls. 💡 Pro Tip: If your API tab in DevTools looks like a machine gun 🔫, you’ve got an infinite loop. Small mistake. Big impact. Debugging this once will make you a better developer forever. Have you ever run into infinite API calls? How did you fix it? 👇 #ReactJS #WebDevelopment #FrontendDevelopment #JavaScript #SoftwareEngineering #Debugging #ProgrammingTips #CleanCode #DevCommunity #ReactDeveloper #WebDevTips #API #PerformanceOptimization #CodeQuality #TechTips
To view or add a comment, sign in
-
-
useEffect is the most abused hook in React. Here's what to use instead. I've reviewed hundreds of React codebases. useEffect is in the wrong place in about 60% of them. Not because developers are careless. Because nobody explained when NOT to use it. Here are the cases I see constantly — and what actually belongs there: // ❌ Case 1: Deriving state useEffect(() => { setFullName(`${firstName} ${lastName}`) }, [firstName, lastName]) // ✅ Just compute it const fullName = `${firstName} ${lastName}` No state. No effect. No re-render bug. // ❌ Case 2: Fetching data on mount (with App Router) useEffect(() => { fetch('/api/user').then(...) }, []) // ✅ Use a Server Component or TanStack Query // Data fetching is not a side effect in modern React // ❌ Case 3: Syncing two pieces of state useEffect(() => { if (selectedId) setDetails(getDetails(selectedId)) }, [selectedId]) // ✅ Derive during render const details = selectedId ? getDetails(selectedId) : null The React team has said explicitly: if you're using useEffect to sync state with other state, you probably have one piece of state too many. useEffect is for: → Connecting to external systems (WebSocket, third-party libraries, browser APIs) → Setting up subscriptions → Manual DOM manipulation That's mostly it. If you're using useEffect for anything that feels like when X changes, update Y, there's almost certainly a cleaner way. What's the strangest useEffect usage you've come across? #React #JavaScript #TypeScript #FrontendDevelopment #WebDevelopment
To view or add a comment, sign in
-
-
I struggled with this React concept more than I expected… 👇 👉 Why are my API calls running twice? ⚙️ What you’ll notice You open your network tab and suddenly see this: api/me → called twice api/roles → called twice api/permissions → called twice Just like in the screenshot 👇 Same request, duplicated… again and again. ⚙️ What’s actually happening In React (development mode), if your app is wrapped in Strict Mode, React will run effects twice on purpose. useEffect(() => { fetch("/api/users") .then(res => res.json()) .then(setUsers); }, []); Even though it looks like it should run once… it doesn’t (in dev). 🧠 What’s going on under the hood React basically does a quick cycle: mount → unmount → remount Why? To catch hidden side effects To check if cleanup is handled properly To make sure your logic doesn’t break on re-renders So if your API call runs twice, React is just making sure your code can handle it. 💡 The important part This only happens in development Production behaves normally (runs once) Your side effects should be safe to run multiple times 🚀 Final thought If your network tab looks “noisy” like the screenshot, it’s not React being broken — it’s React being careful. And once you understand this, debugging becomes a lot less confusing. #React #Frontend #JavaScript #WebDevelopment #ReactJS #SoftwareEngineering
To view or add a comment, sign in
-
⚛️ React.js Cheat Sheet — What Actually Matters React is more than components. It’s a way of thinking about UI. Core ideas🚀 🚀 Component-based architecture ❄️ Props & state for data flow ❄️ Hooks for logic and lifecycle ❄️ Virtual DOM for performance 🚀 What makes a strong React developer ❄️ Clean component structure ❄️ Smart state management ❄️ Efficient rendering ❄️ Proper data fetching ❄️ Reusable custom hooks ❄️ Beyond the basics ❄️ Code splitting & optimization ❄️ TypeScript integration ❄️ Testing & error boundaries 🎯 React isn’t just about building interfaces. It’s about building scalable, maintainable UI systems. #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #DeveloperSkills
To view or add a comment, sign in
-
-
🚀 Just published a new article on Medium! If you're working with React and APIs, you've probably heard of Axios, but do you really know why it's so widely used? In this article, I break down: ✅ How Axios simplifies API requests ✅ Built-in error handling (and why it matters) ✅ Why it’s often preferred over fetch Whether you're a beginner or sharpening your frontend skills, this will give you a clearer understanding of making efficient API calls in React. #React #JavaScript #WebDevelopment #Frontend #Axios #SoftwareEngineering
To view or add a comment, sign in
-
By default, React is fast. But as data grows, unnecessary re-renders quietly kill performance. Today I learned two hooks that every serious React developer needs to know: 🗒️ useMemo — A cache for heavy calculations. Instead of re-running expensive logic on every render, React stores the result and reuses it. Think of it like a sticky note your genius friend writes so they don't have to solve the same problem twice. 🔗 useCallback — Stabilizes your functions. In JS, functions are objects — so a "new" one gets created on every render. This hook keeps the reference the same, stopping child components from re-rendering for no reason. The senior wisdom I picked up today? Don't over-optimize. These hooks cost memory. Only reach for them when you actually see a lag — not before. Understanding when to optimize is what separates professional developers from the rest. Tomorrow: I'm building my own tools with Custom React Hooks! 👀 Question for you: Do you optimize as you go, or wait until something feels slow? Drop your strategy below 👇 #CodeWithWajid #ReactJS #WebDevelopment #100DaysOfCode #LearningToCode #BuildingInPublic #ReactOptimization #WebPerf
To view or add a comment, sign in
-
𝗣𝗮𝗿𝗹𝗲𝘇-𝘃𝗼𝘂𝘀 𝗥𝘂𝗯𝘆? Imagine a way to write computer code that was designed around humans. Designed to be beautiful. Readable. Expressive. Enjoyable. That's Ruby. Want to look up someone's last chat message? In Ruby on Rails: current_user.chats.last.user_messages.last Ruby on Rails is not the dominant paradigm - though sites like GitHub, Shopify, Basecamp etc run it. The codebase tends to be smaller. Once you're read in - it's so much easier. It just makes sense. What's most popular? Javascript - esp Node/React. Javascript was written to run in early web browsers. So, a very different design goal. Same concept in Javascript? // Database const chats = await Chat.find({ userId }).sort({ createdAt: -1 }).limit(1) const messages = await Message.find({ chatId: chats[0]._id }).sort({ createdAt: -1 }).limit(1) // API endpoint app.get('/last-message', async (req, res) => res.json(messages[0])) // React frontend const [lastMessage, setLastMessage] = useState(null) useEffect(() => { fetch('/last-message').then(r => r.json()).then(setLastMessage) }, []) Three layers. Three files. Three places to break. And then there's that beauty thing. More, from the creator of Rails, at https://lnkd.in/gv_en552 #ruby #rubyonrails #javascript #react #webdev #programming #DHH
To view or add a comment, sign in
-
-
🚀 React Project: JSON Explorer I built a small web application that allows users to paste any JSON API URL and instantly visualize the returned data in a clean and structured format. Key Features ✔ Fetch data from any JSON API ✔ Loading and error handling ✔ Clean UI for easy JSON visualization ✔ “Load More” functionality for large datasets Tech Stack: React | JavaScript | CSS 🔗 Try the app: https://lnkd.in/gQDirDAn This project helped me strengthen my understanding of API integration, React state management, and dynamic UI rendering. #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #API #LearningByBuilding
To view or add a comment, sign in
Explore related topics
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