title: Socket.io not emitting messages to a specific user
body: <p>I have a chat app with node.js, socket io, and React.js. The issue: the private message featureis not working.</p>
  <p>Client-side:</p>
  <pre><code>socket.emit(&quot;chat message private&quot;, { userIDtoReceiveTheMessage, msg });
  </code></pre>
  <p>Then my server will listen and emit to that specific user:</p>
  <pre><code>  socket.on(&quot;chat message private&quot;, ({ toUser, msg }) =&gt; {
      console.log(`from ${id} to ${toUser}: ${msg}`);
      let socketId = toUser;
      io.to(socketId).emit(&quot;private msg&quot;, msg);
    });
  </code></pre>
  <p>The result on the console for the server is:
  &quot;from X to Y: message&quot; <strong>(this is workings!)</strong></p>
  <p>My client should receive &quot;msg&quot;, but nothing happens:</p>
  <pre><code>  useEffect(() =&gt; {
      socket.on(&quot;chat message&quot;, ({ nickname, msg }) =&gt; {
        setChat([...chat, { nickname, msg }]);
      });
  
      socket.on(&quot;private msg&quot;, (msg) =&gt; {
        console.log(msg);
        setChat([...chat, msg]);
      });
  
      return () =&gt; {
        socket.off();
      };
    }, [chat, toUser]);
  </code></pre>
  <p>Nothing shows up on the console for the specific user (or for any user).</p>
  <p>PS: All other chat messages are being received in real-time. The only issue is with the ones using:</p>
  <pre><code>io.to(socketId).emit(&quot;private msg&quot;, msg);
  </code></pre>
  <p>Any suggestions?</p>