Course contentsShow
← React
Lesson 538 of 2,39615. useEffect FundamentalsFree lesson

No Array: Run on Every Render

See what happens when you omit the dependency array entirely—your effect runs after every single render.

No Array: Run on Every Render

You'll learn what happens when you completely omit the dependency array from useEffect—and why it's usually a mistake.

The Default Behavior

When you write useEffect without the second argument (the dependency array), your effect runs after every single render of your component:

useEffect(() => {
  console.log('This runs after EVERY render');
});

No dependency array at all means: "React, please run this effect after the component renders, every time, no exceptions."

Why This Usually Creates Problems

Since effects run after every render, and since setting state triggers a render, you can easily create infinite loops:

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

  useEffect(() => {
    setCount(count + 1); // ⚠️ Infinite loop!
  });

  return <div>{count}</div>;
}

This component renders → effect runs → sets state → component re-renders → effect runs again → sets state → re-renders... forever.

The Analogy

Imagine telling someone: "After I finish any sentence, interrupt me." You'd never finish a conversation! That's what omitting the dependency array does—your effect constantly interrupts the natural render cycle.

When Would You Use This?

Almost never. The only legitimate case is when you genuinely need to synchronize with something external on every render, which is extremely rare. Usually, you want either an empty array (run once) or a specific dependency array (run when those values change).

Key Takeaway: Omitting the dependency array makes your effect run after every render, which usually causes performance problems or infinite loops. Always include the dependency array—even if it's empty.