tezvyn:

Explain useEffect dependency array behavior for [], [deps], and omitted

Source: react.devbeginner

It tests reactive dependency tracking. Omitting re-runs every render; [] runs on mount with cleanup on unmount; [deps] re-runs when Object.is detects change. Red flag: claiming [] means 'run once' without mentioning cleanup or stale values.

It tests whether you understand how React schedules Effect re-execution based on reactive values. Omitting the array causes the Effect to run after every commit; [] limits it to mount and triggers cleanup on unmount; [prop1, state2] re-runs only when Object.is detects a change. A strong answer notes that [] still runs cleanup on unmount and may re-run in Strict Mode. Red flag: describing [] as 'run once' while ignoring cleanup, stale closures, or the linter rule.

Read the original → react.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Explain useEffect dependency array behavior for [], [deps], and omitted · Tezvyn