title: react-router-dom useHistory() not working
body: <p>The <strong>useHistory()</strong> hook is not working in my project. I have it in different components but none of them work.
  I am using &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,</p>
  <pre><code>import {useHistory} from 'react-router-dom'
  
  const history = useHistory()
  
  const logout = () =&gt; {    
     toggleMenu()
     setUser(null)
     dispatch({type: 'LOGOUT'})
     history.push('/')
  }
  </code></pre>
  <p>And also in action its not working</p>
  <pre><code>export const signin = (formdata, history, setError) =&gt; async (dispatch) =&gt; {
  try {
      const {data} = await API.signIn(formdata)
      if(data.error){
          setError(data.message)
      }else{
          dispatch({type: SIGNIN, data})
          history.push('/dashboard')
      }
  
     } catch (error) {
      setError(error)
      console.log(error)
    }
  }
  </code></pre>
  <p>Here is my router.js file</p>
  <pre><code>const Router = () =&gt; {
      const user = JSON.parse(localStorage.getItem('profile'))
      return (
         &lt;BrowserRouter&gt;
                  &lt;&gt;
                      {user &amp;&amp; &lt;Navigation/&gt;}
                      &lt;Switch&gt;
                          &lt;Route path='/page-not-found' component={Auth}/&gt;
                          &lt;Route path='/' exact component={()=&gt;((user &amp;&amp; user.result) ? &lt;Redirect to=&quot;/dasboard&quot;/&gt; : &lt;Auth/&gt;)} /&gt;
                          
                          &lt;Route path='/dashboard' component={() =&gt; (user ? &lt;Dashboard/&gt; : &lt;Redirect to='/'/&gt;)} /&gt;
                          &lt;Route path='/books-purchase' component={() =&gt; (user ? &lt;BooksPage/&gt; : &lt;Redirect to='/' /&gt;)} /&gt;
                      
                      &lt;/Switch&gt;
                  &lt;/&gt;
              
          &lt;/BrowserRouter&gt;
        )
    }
  </code></pre>