How does the dependency array in useEffect relate to cleanup?
When dependencies in a useEffect's dependency array change, React runs the cleanup function from the previous render before executing the effect again. Additionally, the cleanup function will run when the component unmounts. This ensures proper resource management when dependencies change and when the component is removed from the DOM.