The useEffect hook in React allows you to synchronize a component with an external system by performing side effects like data fetching, subscriptions, or DOM updates. It replaces class-based lifecycle methods such as componentDidMount, componentDidUpdate, and componentWillUnmount.

By default, the effect function runs after every render, but you can control execution using a dependency array as the second argument:

  • No dependency array: Runs after every render.

  • Empty dependency array ([]): Runs only once after the initial mount (similar to componentDidMount).

  • Array with variables (e.g., [count]): Runs when any of the specified variables change.

The effect function can optionally return a cleanup function, which React executes before the effect runs again or when the component unmounts to prevent memory leaks. This cleanup is essential for clearing timers, removing event listeners, or aborting network requests.

Syntax and Usage:

useEffect(() => {
  // Setup logic (e.g., connect to API, set interval)
  
  return () => {
    // Cleanup logic (e.g., disconnect, clear interval)
  };
}, [dependency1, dependency2]); // Optional dependency array

Key behaviors include:

  • Asynchronous Logic: The effect function itself cannot be async, but you can define an inner async function and call it immediately.

  • Development Mode: React runs setup and cleanup twice during the first render in development to verify that cleanup logic correctly mirrors setup logic.

  • Dependencies: React compares dependencies using Object.is; if omitted, the effect runs on every commit.

  • Scope: It only runs on the client side and does not execute during server rendering.

As other answers have said, don’t avoid them - just use them with intention. This is a fantastic, official resource for knowing when to avoid using one: https://react.dev/learn/you-might-not-need-an-effect As the above dives into, it’s not just for performance. I’ve seen plenty of bugs and layout flickers that have resulted from incorrect uses of useEffect, particularly when state is changed inside the effect callback. Answer from santaschesthairs on reddit.com
🌐
React
react.dev › reference › react › useEffect
useEffect – React
See the difference between passing an array of dependencies, an empty array, and no dependencies at all. ... useEffect is a Hook, so you can only call it at the top level of your component or your own Hooks.
🌐
W3Schools
w3schools.com › react › react_useeffect.asp
React useEffect
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep React Bootcamp React Certificate ... The useEffect Hook allows you to perform side effects in your components.
🌐
Reddit
reddit.com › r/reactjs › [noob] are useeffect hooks really that bad??
r/reactjs on Reddit: [Noob] are useEffect hooks really that bad??
February 10, 2025 -

am a junior full stack dev and my experience with react are limited to school projects. i've always use useEffect hooks and everything is great until i heard my senior devs complaining about the team using too many useEffect hooks in our codebase. things like our components get rendered unnecessarily and slowing down performance. ever since then, i'm very conscious about using useEffect.

so question is, are useEffect hooks really that bad and should i avoid using them at all cost? love to hear from yall cuz this is bothering me a lot and i want to be a better engineer

🌐
DEV Community
dev.to › louizamak › the-beginners-guide-to-reacts-useeffect-hook-5djl
The Beginner's Guide to React's useEffect Hook - DEV Community
July 18, 2024 - In conclusion, the useEffect hook is an incredibly essential tool for managing side effects in React functional components. It's versatile and simple and can handle a wide range of scenarios such as fetching data, subscribing to events, and ...
🌐
React
legacy.reactjs.org › docs › hooks-effect.html
Using the Effect Hook – React
By using this Hook, you tell React that your component needs to do something after render. React will remember the function you passed (we’ll refer to it as our “effect”), and call it later after performing the DOM updates.
🌐
Mimo
mimo.org › glossary › react › useeffect-hook
React useEffect Hook: Syntax, Usage, and Examples
The React useEffect hook lets you synchronize a component with external systems. It replaces lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount from class-based components.
🌐
PureCode AI
blogs.purecode.ai › home › how to master react useeffect to build great applications
How to Master React useEffect to Build Great Applications - Blogs
October 1, 2025 - Introduced in React 16.8, useEffect allows you to perform side effects in function components. Side effects could be data fetching, subscriptions, or manually changing the DOM, among others.
Find elsewhere
🌐
Medium
medium.com › @shankavieducationalinstitute › mastering-react-useeffect-ef4acc64cbf1
Mastering React useEffect
November 28, 2023 - Mastering React useEffect React’s useEffect hook is a powerful tool for handling side effects in functional components. Whether you’re fetching data, subscribing to events, or performing cleanup …
🌐
Dave Ceddia
daveceddia.com › useeffect-hook-examples
How the useEffect Hook Works (with Examples)
October 22, 2020 - The useEffect hook is the Swiss Army knife of all the hooks. It’s the solution to many problems: how to fetch data when a component mounts, how to run code when state changes or when a prop changes, how to set up timers or intervals, you name it. Pretty much anything you want to “do” in a React component other than return JSX (any sort of side effect), will go into a useEffect.
🌐
SitePoint
sitepoint.com › blog › javascript › understanding react useeffect
Understanding React useEffect — SitePoint
February 17, 2024 - The React useEffect hook is a powerful tool in the React developer’s arsenal. It allows you to perform side effects in your functional components, such as data fetching, subscriptions, or manually changing the DOM.
🌐
Effect
effect.website
Effect – The best way to build robust apps in TypeScript
Effect is a powerful TypeScript library designed to help developers easily create complex, synchronous, and asynchronous programs.
🌐
Next.js
nextjs.org › docs › messages › react-hydration-error
Text content does not match server-rendered HTML | Next.js
import { useState, useEffect } from 'react' export default function App() { const [isClient, setIsClient] = useState(false) useEffect(() => { setIsClient(true) }, []) return <h1>{isClient ?
🌐
useHooks
usehooks.com
useHooks – The React Hooks Library
A collection of modern, server-safe React hooks – from the ui.dev team
🌐
Epic React
epicreact.dev › myths-about-useeffect
Myths about useEffect | Epic React by Kent C. Dodds
July 9, 2024 - So, in our example, all we care about is: "When the dogId changes, fetch the new dog's information." With that as our goal, useEffect becomes much simpler for this case: ... 🤯 Oh snap. That's way better right?! When the React team introduced hooks, their goal wasn't to simply add lifecycles to function components.
🌐
Overreacted
overreacted.io › a-complete-guide-to-useeffect
A Complete Guide to useEffect — overreacted
March 9, 2019 - There is no distinction between a “mount” or an “update” when rendering. You should think of effects in a similar way. useEffect lets you synchronize things outside of the React tree according to our props and state.
🌐
DEV Community
dev.to › vidya_varshini › useeffect-in-react-4ebc
useEffect in React - DEV Community
October 27, 2025 - What is useEffect: It is a react hook which helps to run side effects in the functional components....
🌐
freeCodeCamp
freecodecamp.org › news › react-hooks-useeffect-usestate-and-usecontext
How to Use React Hooks – useEffect, useState, and useContext Code Examples
December 4, 2023 - The useEffect hook is used to perform side effects in your functional components, such as fetching data, subscribing to external events, or manually changing the DOM. It combines the functionality of componentDidMount, componentDidUpdate, and ...
🌐
Hygraph
hygraph.com › blog › react-useeffect-a-complete-guide
React useEffect() - A complete guide | Hygraph
January 21, 2026 - Class-based components and lifecycle methods are rarely used in modern React development. As mentioned, the useEffect Hook allows you to perform common side effects in function components.