Mr. Harun’s count on the neighbourhood head’s screen: a real useEffect starts a setInterval, pick the deps [], [count], [opsi] or none, then the order of…
Why it matters
useEffect deps are React’s number one bug source. Knowing why an interval uses an old value ([]) or why your app renders forever (no array) is the difference between a two-minute debug and a two-hour one.
The key idea
The deps decide WHEN the effect runs again, and which values it holds
Common mistakes
The UI shows a new number, but the console keeps shouting the old value every second The effect uses count but its deps are []: a stale closure. Put count in the deps, or use the updater setCount(c => c + 1). ESLint’s react-hooks/exhaustive-deps catches it; do not switch it off lightly.
The effect keeps running even though the deps are filled in, it never settles[opsi] with const opsi = { ... } made during render: a new object every render, so it always "changed". useMemo the object, move it out of the component, or put its primitive value in the deps (opsi.tempo).
The tab freezes, React throws 'Maximum update depth exceeded' render → effect → setState → render... without end. Give it the right deps ([] for once), or guard it with a condition. React’s development build warns after 50 rounds; the production build says nothing.
Try it in this playground
Play deps [] with count + 1 The number sticks at 1: every second the interval calls setCount(0 + 1) with the first render’s count.
Switch the deps to [count] Every beat: the old interval cleaned up, a new effect with the latest count. One interval alive.
Try c => c + 1 with [] It keeps climbing with an effect that runs once: the updater gets the latest value from React.
Strike the gong with no array (or with [opsi]) The parent renders again, count is unchanged, yet the effect runs again: cleanup, then setup.