Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created February 19, 2020 17:08
Show Gist options
  • Save sibelius/7d760fa16a121ec0f4cd8b143a59bee6 to your computer and use it in GitHub Desktop.
Save sibelius/7d760fa16a121ec0f4cd8b143a59bee6 to your computer and use it in GitHub Desktop.
withRouter for react-router-dom v6
import { useHistory } from 'react-router-dom';
export const withRouter = (Component) => {
const Wrapper = (props) => {
const history = useHistory();
return (
<Component
history={history}
{...props}
/>
);
};
return Wrapper;
};
@RaduRS
Copy link

RaduRS commented Feb 2, 2022

  <button onClick={() => {navigate("/dashboard");}} >
        Dashboard
  </button>

@SateeshKumbhakar
Copy link

I tried this, Thank you @RaduRS

@PavelHasala
Copy link

Can somebody help me, how to type the Component parameter, so it is not any, when passing class components?

Copy link

ghost commented Jun 14, 2022

useNavigate working perfectly...

Okay Bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment