Cleanup chạy:
- trước mỗi lần effect re-run khi dependencies thay đổi
- khi component unmount. Quan trọng để tránh memory leaks: hủy subscriptions, abort fetch requests, clear timers
Ví dụ: return () => controller.abort() trong fetch effect.
The cleanup runs:
- before each effect re-run when dependencies change, and
- when the component unmounts. It is critical for preventing memory leaks: cancelling subscriptions, aborting fetch requests, and clearing timers
Example: return () => controller.abort() inside a fetch effect.