title: How to redirect user after submitting form with React
body: <p>I'm learning React. I have a login page with a form ("/login") which after submitting successfully I wanna redirect the user to the root path ("/") of the domain. I'm using Redux that seems to work fine. My code is:</p>
  
  <pre><code>const handleSubmit = (e) =&gt; {
  
          e.preventDefault()
  
          setSubmitBtn(true)
  
          setTimeout(async (e) =&gt; {
  
              const { data } = await axios.post( axiosURL + '/login', inputs)
  
              dispatch({ type: 'LOGIN' })
  
              history.push("/")
  
              setReturnMessage(data.message)
  
              setSubmitBtn(false)
  
          }, 1000)
      }
  </code></pre>
  
  <p>The problem is the <code>history.push("/")</code> that's not working and it gives the following error message:</p>
  
  <pre><code>Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
      in Login (created by Context.Consumer)
      in Route (at routes.js:36)
  </code></pre>
  
  <p>Does anyone know how to fix it? Thanks!!</p>