title: TypeError: Cannot read properties of null (reading 'emit')
body: <pre><code>import { io } from &quot;socket.io-client&quot;;
  import { useState, useEffect } from &quot;react&quot;;
  
  const Game = () =&gt; {
  
    const [socket, setSocket] = useState(null);
    const [name, setName] = useState(&quot;&quot;);
    const [room, setRoom] = useState(&quot;&quot;);
  
    useEffect(() =&gt; {
      setSocket(io(process.env.REACT_APP_BASE_URL));
  
      return () =&gt; {
        socket.emit(&quot;disconnect&quot;);
      };
    }, [socket]);
  
    const sendMessage = () =&gt; {
      socket.emit(&quot;room1&quot;, { name, room });
      socket.off();
    };
  
    return (
      ...
    );
  };
  
  export default Game;
  </code></pre>
  <p>Hi all.As in the title I am getting this error.If i delete <code>socket</code> in useEffect dependency i dont get this error anymore but this time i get <code>React Hook useEffect has a missing dependency: 'socket'. Either include it or remove the dependency array  react-hooks/exhaustive-deps</code> error.</p>