247
effect dependencies
also useEffect deps
The dependency array is the list of values the effect reads. An empty array means mount and unmount only.
What is effect dependencies?
An effect re-runs when a dependency changes, and its cleanup runs before the next run and on unmount. Every reactive value the effect reads belongs in the array. An empty array is a promise that the effect does not read props or state. A comment that silences the lint is a lie about that promise.
Why does effect dependencies matter when vibe coding?
Generated effects copy a value into the array or omit it to stop a loop. The effect keeps the first props forever, or it runs on every render and retriggers itself.
How do you do effect dependencies?
List what you read. If a value should not retrigger the effect, do not read it, or put the latest copy in a ref on purpose. Move derived work out of the effect.
How do you ask a model for effect dependencies?
The effect in (component) depends on (values). Include every value it reads. Do not silence the lint. If a value must not retrigger it, keep the latest copy in a ref and say why.
What goes wrong with effect dependencies?
An object or function literal in the array, created each render, so the effect runs every time. Stabilize it or move it inside.