Here are the three scenarios: 1- No dependency array >> code inside useEffect runs every time your component re-renders. 2- Empty dependency array >> code inside your useEffect only runs once when your component first mounts. 3- Not-empty dependency array >> code inside your useEffect runs every time any variables you put inside the dependency array change. The last part isn't exactly accurate. You components also needs to re-render. so if your put a state or a prob inside your dependency array, your component will re-render and the useEffect will run. However, if you put some kind of a const or locally defend variable that doesn't trigger a re-render when it's changed, the useEffect will only fire again with the next re-render. Answer from ritwal on reddit.com
🌐
React
react.dev › reference › react › useEffect
useEffect – React
The rule of thumb is that the user shouldn’t be able to distinguish between the setup being called once (as in production) and a setup → cleanup → setup sequence (as in development). Read more about how this helps find bugs and how to fix your logic. First, check that you haven’t forgotten to specify the dependency array:
🌐
Devtrium
devtrium.com › posts › dependency-arrays
What are dependency arrays in React? - Devtrium
August 8, 2021 - It's a pretty simple rule, made a bit harder by some exceptions. The rule is: if any variable is used inside the hook but is defined outside of it, then it should go in the dependency array....
Discussions

reactjs - useEffect dependency array and ESLint exhaustive-deps rule - Stack Overflow
React Hook useEffect has missing dependencies: id and onChange. Either include them or remove the dependency array. (react-hooks/exhaustive-deps)eslint · I know that id and onChange are not going to change, so adding them to the dependency array seems unnecessary. But the rule isn't a warning, ... More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Passing array to useEffect dependency list - Stack Overflow
@LoiNguyenHuynh: I know why the ... passing arrays or objects to useEffect/useMemo/useCallback's dependencies really keeps coming back to me and I'm starting to get tired of using work-arounds. Is there any way we can discuss improvements somewhere? I don't know where to start. 2020-08-31T22:42:46.543Z+00:00 ... This causes ESLint to warn both about a missing dependency and a complex expression - both under the react-hooks/exhaustive-deps rule, which I really ... More on stackoverflow.com
🌐 stackoverflow.com
Adding an array in the useEffect dependency array causes an infinte loop
yes, so this would be the expected behavior. Any time the contents of that dependency array change, that first argument, the callback function, will be run again. So, you are setting tasks in the API call, which changes the contents of that dependency array, which calls that callback again, which sets state again, in an infinite loop. There are two solutions for you here. Either, remove tasks from that dependency array, which violates the "exhaustive deps" rule, whereby the react team strongly recommends having all dependencies of that function in the dependency array, or you can just leave the second argument as is and write if(!tasks.length) {...} or if(task.length === 0) {...} before making the API call, so it only runs once. You can find some more info about this in the extremely helpful react documentation: https://reactjs.org/docs/hooks-effect.html More on reddit.com
🌐 r/reactjs
16
4
December 26, 2020
Array in useEffect dependency array

Are you mutating the array? Can you post the code that you’re using to change the array itself?

More on reddit.com
🌐 r/reactjs
4
5
August 13, 2019
People also ask

Can you use objects or arrays in the useEffect dependency array?
Yes, but JavaScript compares object or array references, not their contents. This can cause unnecessary re-renders. To avoid this, use the useMemo hook to memoize objects or arrays used in the dependency array.
🌐
dhiwise.com
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array
What happens if you don’t pass a dependency array to useEffect?
Without a dependency array, the effect runs after every render. This can lead to performance issues and bugs since the effect won't re-run based on changes in specific dependencies.
🌐
dhiwise.com
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array
What is the useEffect hook used for in React?
The useEffect hook in React allows developers to manage side effects like data fetching, DOM manipulation, or subscriptions within functional components. It helps control when these side effects should be executed by specifying dependencies.
🌐
dhiwise.com
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array
🌐
Reddit
reddit.com › r/reactjs › can someone explain useeffect dependency arrays like im 5?
r/reactjs on Reddit: Can someone explain useEffect dependency arrays like im 5?
April 24, 2022 -

When do you need to use it? Why do I need to put a empty array even though its empty? When would I put something in the empty array?

Sorry if stupid noob question.

🌐
Medium
egebilge.medium.com › best-practices-for-useeffect-dependency-arrays-in-react-fcb53ef55495
🎯 Best Practices for useEffect Dependency Arrays in React | by Ege Bilge | Medium
April 24, 2025 - “The function passed to useEffect will run after the render is committed to the screen.” — React Docs · React encourages developers to focus on actual data dependencies, not function identities — especially when dealing with state setters or memoized callbacks. By excluding setter functions from your dependency arrays:
🌐
DhiWise
dhiwise.com › post › understanding-the-importance-of-the-useeffect-dependency-array-in-react
UseEffect Dependency Array
August 13, 2025 - This helps you visualize how React decides whether to run the useEffect callback function. 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.
🌐
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.
Find elsewhere
🌐
React
react.wiki › home › react hooks › useeffect dependency array: deep mechanics explained
useEffect Dependency Array: Deep Mechanics Explained | react.wiki
January 1, 2026 - React uses a surprisingly simple mechanism to track dependencies. After each render, React compares the new dependency array with the previous one, element by element, using strict equality.
Top answer
1 of 2
29

Old Answer

Actually the rule is very straightforward: Either pass an array containing all dependencies, or don't pass anything. So I guess the rule isn't dumb, it just doesn't know if the dependencies are going to change or not. So yes, if you are passing an array of dependencies it should contain ALL dependencies, including those you know for a fact that will not change. Something like this will throw a warning:

useEffect(() => dispatch({ someAction }), [])

And to fix this you should pass dispatch as a dependency, even though it will never change:

useEffect(() => dispatch({ someAction }), [dispatch])

Don't disable the exhaustive deps rule, as mentioned here


UPDATE 05/04/2021

As addressed here. This is no longer necessary since eslint pull #1950.

Now referential types with stable signature such as those provenients from useState or useDispatch can safely be used inside an effect without triggering exhaustive-deps even when coming from props

2 of 2
7

The way to look at it is every render has its own effect. If the effect will be the same with a particular set of values, then we can tell React about those values in the dependencies array. Ideally, a component with the same state and props, will always have the same output (rendered component + effect) after its render and effect is done. This is what makes it more resilient to bugs.

The point of the rule is that, if the deps DO change, the effect SHOULD run again, because it is now a different effect.

These 3 links also give more insights about this:

  • https://github.com/facebook/react/issues/14920#issuecomment-471070149
  • https://overreacted.io/a-complete-guide-to-useeffect/
  • https://overreacted.io/writing-resilient-components/
🌐
Retool
retool.com › blog › hooks-and-state-102-the-dependency-array-in-useeffect
Hooks and state 102: the Dependency array in useEffect()
July 9, 2025 - If you have an object or array as a dependency of useEffect, and then update that object inside the effect, you effectively create a new object with a new reference and cause an infinite loop.
🌐
Bitstack
blog.bitsrc.io › understanding-dependencies-in-useeffect-7afd4df37c96
Understanding Dependencies in useEffect | Bits and Pieces
March 4, 2025 - Rows indicate when the effect should run, columns show the actual dependencies of the effect, and cells specify the array of dependencies to be used when calling useEffect. Now if you look at the table, I have also added some yellow where the ...
Top answer
1 of 7
195

You can pass JSON.stringify(outcomes) as the dependency list:

Read more here

useEffect(() => {
  console.log(outcomes)
}, [JSON.stringify(outcomes)])
2 of 7
23

Using JSON.stringify() or any deep comparison methods may be inefficient, if you know ahead the shape of the object, you can write your own effect hook that triggers the callback based on the result of your custom equality function.

useEffect works by checking if each value in the dependency array is the same instance with the one in the previous render and executes the callback if one of them is not. So we just need to keep the instance of the data we're interested in using useRef and only assign a new one if the custom equality check return false to trigger the effect.

function arrayEqual(a1: any[], a2: any[]) {
  if (a1.length !== a2.length) return false;
  for (let i = 0; i < a1.length; i++) {
    if (a1[i] !== a2[i]) {
      return false;
    }
  }
  return true;
}

type MaybeCleanUpFn = void | (() => void);

function useNumberArrayEffect(cb: () => MaybeCleanUpFn, deps: number[]) {
  const ref = useRef<number[]>(deps);

  if (!arrayEqual(deps, ref.current)) {
    ref.current = deps;
  }

  useEffect(cb, [ref.current]);
}

Usage

function Child({ arr }: { arr: number[] }) {
  useNumberArrayEffect(() => {
    console.log("run effect", JSON.stringify(arr));
  }, arr);

  return <pre>{JSON.stringify(arr)}</pre>;
}

Taking one step further, we can also reuse the hook by creating an effect hook that accepts a custom equality function.

type MaybeCleanUpFn = void | (() => void);
type EqualityFn = (a: DependencyList, b: DependencyList) => boolean;

function useCustomEffect(
  cb: () => MaybeCleanUpFn,
  deps: DependencyList,
  equal?: EqualityFn
) {
  const ref = useRef<DependencyList>(deps);

  if (!equal || !equal(deps, ref.current)) {
    ref.current = deps;
  }

  useEffect(cb, [ref.current]);
}

Usage

useCustomEffect(
  () => {
    console.log("run custom effect", JSON.stringify(arr));
  },
  [arr],
  (a, b) => arrayEqual(a[0], b[0])
);

Live Demo

🌐
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 - You should use ++code>react-hooks/exhaustive-deps++/code> eslint rule and refactor your code in this order: Think about if the useEffect is useful or if it should be refactored · Declare the function in the useEffect when it is used only in the useEffect · Memoize the function and add it to the dependency array if it is used in several places
🌐
Medium
medium.com › @navneetskahlon › understanding-the-useeffect-dependency-array-in-react-a-comprehensive-guide-7da9411c90b3
Understanding the useEffect Dependency Array in React: A Comprehensive Guide | by Navneet Singh | Medium
June 20, 2023 - It is important to explicitly define ... When working with the useEffect dependency array, it is crucial to include every state variable and prop that is used inside the effect....
🌐
DEV Community
dev.to › cybermaxi7 › mastering-useeffect-rules-best-practices-and-pitfalls-353e
Mastering useEffect: Rules, Best Practices, and Pitfalls - DEV Community
September 24, 2023 - Every state variable, prop, or context used inside the effect must find its place in this array. It ensures that your effect runs whenever any of these values change. Reactivity Matters: Reactive values are the lifeblood of useEffect.
🌐
egghead.io
egghead.io › lessons › react-manage-the-useeffect-dependency-array
Manage the useEffect dependency array | egghead.io
This normally won’t lead to bugs (in fact, it does a great job at preventing bugs that plagued React apps before useEffect was available), but it can definitely be sub-optimal (and in some cases can result in an infinite loop). In this lesson we’ll observe that our effect callback is getting called more than it needs to be, and you’ll learn how to add a dependency array so it is updated only when the state it relies on changes. And in real applications, you’ll want to make sure you have and follow the rules from the ESLint plugin: eslint-plugin-react-hooks (many tools like Create React App have this installed and configured by default).
Published   March 10, 2020
🌐
Wolfco
wolfco.us › home page › react dependency arrays
React Dependency Arrays - Wolfco
July 24, 2024 - Consider using the array length in your dependency array. That way it will only run if the length of the array changes. Bonus: the length is a primitive. const [items, setItems] = useState([{ id: 1, name: 'Item 1' }]); const itemsLength = ...
Price   $
Call   703-596-5326
Address   Wheaton
🌐
Medium
medium.com › devil-is-in-the-details › dependency-array-in-useeffect-hook-d73e0ef2ab33
Dependency array in useEffect hook | by Shreejit Rajbanshi | Devil is in the Details | Medium
November 20, 2022 - Our code inside the callback will run once when the component gets registered, and that is it. The useEffect hook acts like componentDidMount method if an empty array is passed as the dependency array.
🌐
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 - ... 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 ...
🌐
Ben Ilegbodu
benmvp.com › blog › object-array-dependencies-react-useEffect-hook
Object & array dependencies in the React useEffect Hook | Ben Ilegbodu
January 2, 2021 - React checks to see if the object in the current render points to the same object in the previous render. The objects have to be the exact same object in order for useEffect to skip running the effect.