Effect cleanup
Effect cleanup is the function returned by a React useEffect that releases resources or reverses work performed by the effect. In this course, cleanup marks the socket lifecycle as stopped, cancels pending reconnection timers, and closes the active WebSocket when the component unmounts or its dependencies change.
Minimal example
useEffect(() => {
const socket = new WebSocket(url);
return () => {
socket.close();
};
}, [url]);