title: How do I send a websocket when user reconnects form wifi before it was disconnected in React Native?
body: <p>I want to emit a socket when user reconnects from a wifi before it was disconnected. However, it is not getting sent. Any ideas why?</p>
  <pre><code>const [isConnected, _setIsConnected] = useState(true);
  const isConnectedRef = useRef(isConnected)
  
  NetInfo.addEventListener(state =&gt; {
        if(!isConnectedRef.current &amp;&amp; state.isConnected){
          socket.emit(&quot;socket-reconnected&quot;)
        } else if(isConnectedRef.current &amp;&amp; !state.isConnected){
          socket.emit(&quot;socket-disconnected&quot;);
        }
  
        setIsConnected(state.isConnected);
      });
  </code></pre>