I'm guessing the only difference is that useEffect will guarantee that it will always run after the render, it also makes sure that every other component that needs to re-render will finish rendering before running the effect. Though I can't really think of a good use case for this. Answer from ImprovementReady4791 on reddit.com
🌐
Reddit
reddit.com › r/reactjs › what is the purpose of useeffect without a dependency array?
r/reactjs on Reddit: What is the purpose of useEffect without a dependency array?
March 3, 2022 -

I use useEffect all the time in my applications, but I've never understood the difference between having code inside a useEffect with no dependency array, and just running it in the component itself.

From the documentation. What is the difference between this

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  });
}

and this?

function Example() {
  const [count, setCount] = useState(0);
  document.title = `You clicked ${count} times`;
}

wont both run on every render?

Edit: thanks for all the helpful responses. It seems like my intuition was almost right. It does behave slightly differently, but almost never in a way you want. However it would be good for protecting DOM manipulating functions for SSR.

🌐
React
react.dev › reference › react › useEffect
useEffect – React
If you omit this argument, your Effect will re-run after every commit of the component. 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.
Discussions

reactjs - In useEffect, what's the difference between providing no dependency array and an empty one? - Stack Overflow
I gather that the useEffect Hook is run after every render, if provided with an empty dependency array: ... Notice the lack of [] at the end. More on stackoverflow.com
🌐 stackoverflow.com
Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error
Below is an example component (full component LINK) which is causing a linter error if not disabled. This issue propbably relates to #16265 ;-) A clean up useEffect given an empty dependency array, using a props method causes an error React Hook useEffect has a missing dependency: 'props'. More on github.com
🌐 github.com
11
September 4, 2023
Why does eslint warn about useEffect having a missing dependency? - react - ReScript Forum
Some form of analysis might be able to help with this. Hard to say precisely without fully understanding the problem. To aid understanding: is this a react-specific idiosyncrasy or is it common to all UI frameworks? More on forum.rescript-lang.org
🌐 forum.rescript-lang.org
July 13, 2022
Bug: useEffect with no dependencies always fires a warning
Using useEffect with an empty dependency array will fire up the warning 'react-hooks/exhaustive-deps'. However, using useEffect with an empty dependency list should be a safe praxis when using it as the equivalent of onComponentDidMount. ... Use useEffect with no dependencies. More on github.com
🌐 github.com
2
January 1, 2021
Top answer
1 of 1
65

For this exact case you're right because undefined is passed as the dependencies of useEffect.

This means useEffect runs on every render and thus the event handlers will unnecessarily get detached and reattached on each render.

function listener() {
  console.log('click');
}

function Example() {
  const [count, setCount] = window.React.useState(0);

  window.React.useEffect(() => {

    console.log(`adding listener ${count}`);
    window.addEventListener("click", listener);

    return () => {
      console.log(`removing listener ${count}`);
      window.removeEventListener("click", listener);
    };
  }); // <-- because we're not passing anything here, we have an effect on each render
  
  window.React.useEffect(() => {
    setTimeout(() => {
      setCount(count + 1);
    }, 1000)
  });
  
  return count;
}

window.ReactDOM.render(window.React.createElement(Example), document.getElementById('root'))
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="root"></div>

But if you explicitly declare no dependencies by passing in an empty array [], useEffect will only run once, thus making this pattern perfectly legitimate for event handler attachment.

function listener() {
  console.log('click');
}

function Example() {
  const [count, setCount] = window.React.useState(0);

  window.React.useEffect(() => {

    console.log(`adding listener ${count}`);
    window.addEventListener("click", listener);

    return () => {
      console.log(`removing listener ${count}`);
      window.removeEventListener("click", listener);
    };
  }, []); // <-- we can control for this effect to run only once during the lifetime of this component
  
  window.React.useEffect(() => {
    setTimeout(() => {
      setCount(count + 1);
    }, 1000)
  });
  
  return count;
}

window.ReactDOM.render(window.React.createElement(Example), document.getElementById('root'))
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="root"></div>

🌐
GitHub
github.com › facebook › react › issues › 27333
Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error · Issue #27333 · facebook/react
September 4, 2023 - type AscensionModalProps = { open: boolean; onClose: () => void; member: GangMember; onAscend: () => void; }; export function AscensionModal(props: AscensionModalProps): React.ReactElement { const gang = useGang(); useRerender(1000); //Cleanup if modal is closed for other reasons, ie. ns.gang.ascendMember() useEffect(() => { return () => { props.onClose(); }; }, []); // eslint-disable-line react-hooks/exhaustive-deps // dependency array must be given and empty or modal will not open // React error wants 'props' in dependency or don't use 'props'.
Author   myCatsName
🌐
DEV Community
dev.to › heyitsaastha › useeffect-in-react-3flb
useEffect with and without dependency array in react - DEV Community
May 26, 2021 - As the useEffect does not have dependencies the useEffect get triggered when the page load. ... If we don't put a dependency array, useEffect() will be called on every render.
🌐
React
react.dev › learn › removing-effect-dependencies
Removing Effect Dependencies – React
Now that roomId is not a reactive value (and can’t change on a re-render), it doesn’t need to be a dependency: ... import { useState, useEffect } from 'react'; import { createConnection } from './chat.js'; const serverUrl = 'https://localhost:1234'; const roomId = 'music'; export default function ChatRoom() { useEffect(() => { const connection = createConnection(serverUrl, roomId); connection.connect(); return () => connection.disconnect(); }, []); return <h1>Welcome to the {roomId} room!</h1>; }
Find elsewhere
🌐
ReScript Forum
forum.rescript-lang.org › t › why-does-eslint-warn-about-useeffect-having-a-missing-dependency › 3534
Why does eslint warn about useEffect having a missing dependency? - react - ReScript Forum
July 13, 2022 - Some form of analysis might be able to help with this. Hard to say precisely without fully understanding the problem. To aid understanding: is this a react-specific idiosyncrasy or is it common to all UI frameworks?
🌐
GitHub
github.com › facebook › react › issues › 20530
Bug: useEffect with no dependencies always fires a warning · Issue #20530 · facebook/react
January 1, 2021 - Either no warning is fired for an intentional empty array, or an alternative hook useOnDidMount is added, which is useEffect but without dependencies.
Author   miquelvir
🌐
Kinsta®
kinsta.com › home › resource center › blog › react errors › how to fix the “react hook useeffect has a missing dependency” error
How To Fix the “React Hook useEffect Has a Missing Dependency” Error
October 1, 2025 - The useEffect hook is used to log a message with the value of the count state variable whenever it changes. However, notice that the count variable is not listed in the second argument array (dependency array) of the useEffect hook.
🌐
DhiWise
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array: Best Practices For React ...
August 13, 2025 - Understanding this flow makes it easier to avoid unnecessary re executions. The React hooks exhaustive deps ESLint rule warns when your effect uses variables not listed in the dependency array.
🌐
DEV Community
dev.to › csituma › why-we-use-empty-array-with-useeffect-iok
Why we use empty array with UseEffect - DEV Community
December 10, 2022 - If you do not want the useEffect callback to run on every render, you should pass an empty array as an argument to useEffect. This tells React that the effect does not depend on any values from the component's props or state, so it only needs ...
🌐
Bitstack
blog.bitsrc.io › understanding-dependencies-in-useeffect-7afd4df37c96
Understanding Dependencies in useEffect | Bits and Pieces
March 4, 2025 - It means that the array plays no direct role in ensuring that the effect runs with fresh values (the effect always runs with the value at the time the component is rendered, as we’ve just seen).
🌐
Epic React
epicreact.dev › why-you-shouldnt-put-refs-in-a-dependency-array
Why you shouldn't put refs in a dependency array | Epic React by Kent C. Dodds
July 9, 2024 - But here's an interesting case. What about a custom hook that accepts a ref? ... React Hook React.useEffect has a missing dependency: 'cbRef'. Either include it or remove the dependency array.
🌐
Codedamn
codedamn.com › news › react js
useEffect dependency array in React.js – Complete Guide
June 2, 2023 - The useEffect manages an array that contains the state variables or functions which are kept an eye for any changes. These changes then trigger the callback function. The most basic dependency array would be an empty array. The empty array indicates that the useEffect doesn’t have any dependencies on any state variables.
🌐
Retool
retool.com › blog › hooks-and-state-102-the-dependency-array-in-useeffect
Retool Blog | Hooks and state 102: the Dependency array in useEffect()
July 9, 2025 - But the linter complains that `isDesktop` is not in the dependency array. The correct solution here is to use `isDesktop` and `selectedPatient` to initialize component state variables.
🌐
Medium
medium.com › @kavishkanimsara9919 › understanding-useeffects-dependency-array-in-react-a-complete-guide-c9c2f71059fb
Understanding useEffect’s Dependency Array in React: A Complete Guide | by Kavishka Nimsara | Medium
February 6, 2025 - useEffectis a React Hook that allows us to perform side effects in functional components. Side effects can include fetching data, updating the DOM, or handling timers. ... A side effect is when a function does something that affects the outside world, like fetching data from an API or modifying a variable outside its scope. ... The dependency array in useEffect determines when the effect should run.It controls when the effect executes based on the values inside the array.
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › why use empty dependency array in react's useeffect
Why Use Empty Dependency Array in React's useEffect, by John Kavanagh
October 28, 2025 - As I touched upon back at the start of this article, if you don't pass a dependency array to useEffect at all (i.e., you omit the second argument), then the contents of the effect will run after every single component render or state change.
🌐
Theodo
apps.theodo.com › en › article › how-to-avoid-bugs-in-useeffect
How to manage the useEffect dependency array like a pro?
March 1, 2022 - But ++code>react-hooks/exhaustive-deps++/code> rule raises a warning : React Hook useEffect has a missing dependency: 'fetchAndStoreData'. Either include it or remove the dependency array.