Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
No array runs the effect after every render; an empty array runs it after the first render only; an array of values runs it whenever one of those values changes.
useEffect runs after React has updated the screen. Without a dependency array it runs after every render. With [] it runs once after the component mounts, and its cleanup runs when the component unmounts. With [a, b] React compares each value with the previous render using Object.is and re-runs the effect if any changed. Every reactive value the effect reads, such as props, state or values derived from them, should be listed, otherwise the effect can use stale data.