Created
February 19, 2020 17:08
-
-
Save sibelius/7d760fa16a121ec0f4cd8b143a59bee6 to your computer and use it in GitHub Desktop.
withRouter for react-router-dom v6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useHistory } from 'react-router-dom'; | |
export const withRouter = (Component) => { | |
const Wrapper = (props) => { | |
const history = useHistory(); | |
return ( | |
<Component | |
history={history} | |
{...props} | |
/> | |
); | |
}; | |
return Wrapper; | |
}; |
useHistory is replaced with useNavigate
wait so useNavigate provides the same functionality as withRouter?
useNavigate working perfectly...
hello i am using v6 and I want to redirect (navigate) on the /dashboard
how do I use useNavigate in action.
return navigate('/dashboard') <Navigate to='/dashboard' />
<button onClick={() => {navigate("/dashboard");}} >
Dashboard
</button>
I tried this, Thank you @RaduRS
Can somebody help me, how to type the Component
parameter, so it is not any
, when passing class components?
useNavigate working perfectly...
Okay Bro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use history also not working