Skip to content

Instantly share code, notes, and snippets.

@marabesi
Forked from sibelius/withRouter.tsx
Created November 26, 2021 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marabesi/06bf6e21ff92a980a3fc155145f36d41 to your computer and use it in GitHub Desktop.
Save marabesi/06bf6e21ff92a980a3fc155145f36d41 to your computer and use it in GitHub Desktop.
withRouter for react-router-dom v6
import { useNavigate } from 'react-router-dom';
export const withRouter = Component => {
const Wrapper = (props) => {
const history = useNavigate();
return (
<Component
history={history}
{...props}
/>
);
};
return Wrapper;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment