title: How to redirect in react.js after handling an error
body: <p>Im building a simple app where I want there to be a redirect to the root when there is an error.
  The error is working fine.</p>
  <pre><code>useEffect(() =&gt; {
      const { name, room } = quertString.parse(location.search);
  
      socket = io(ENDPOINT);
   
      setUserName(name);
      setRoomID(room);
  
      socket.emit('join', { name, room }, (error) =&gt; {
        if(error) {
          alert(error)
        }
        return &lt;Redirect to=&quot;./&quot;/&gt;
      });
    }, [ENDPOINT, location.search ]);
  </code></pre>
  <p>what would be the best way for me to do this?
  thanks</p>