I'm trying to update react-router-dom to v6 in my TypeScript React app.
In the offical react-router-dom documentation is simply states:
Along with the upgrade to v5.1, you should replace any usage of
withRouterwith hooks.
It completely ignore class components!
I searched for a long time on the internet, but all the articles I found
- speak about JavaScript rather than TypeScript, or
- speak about function components, or
- refer to v5 (or lower) of
react-router-domsince they speak aboutwithRouter.
Is there a well documented way to upgrade react-router-dom to v6 in a TypeScripp React app which doesn't require to refactor all class components into function components?
withRouterHOC. You can either convert your components to function components or create a customwithRouterHOC using the v6 hooks and injects the "route props" into the decorated components.