React router v6 with Redux Connect function and TS #11612
Replies: 2 comments 1 reply
-
Seems like your Receipt components expects some props, and while the |
Beta Was this translation helpful? Give feedback.
-
Hi, we faced the same issue when migrating to Router v6 while using Redux connect. This does require updating all the connect components to use the Router props from the HOC. // withRouter.tsx HOC
import { useLocation, useNavigate, useParams } from 'react-router-dom';
type WithRouterProps = {
location: ReturnType<typeof useLocation>;
navigate: ReturnType<typeof useNavigate>;
params: ReturnType<typeof useParams>;
};
/** ---
@deprecated Use React Router hooks instead.
--- */
function withRouter<Props extends WithRouterProps>(
Component: React.ComponentType<Props>
) {
function ComponentWithRouterProps(props: Omit<Props, keyof WithRouterProps>) {
const location = useLocation();
const navigate = useNavigate();
const params = useParams();
return (
<Component
{...(props as Props)}
location={location}
navigate={navigate}
params={params}
/>
);
}
return ComponentWithRouterProps;
}
export default withRouter; // App.tsx Class Component (or .jsx)
const AppConnect = connect(mapStateToProps)(App);
export default withRouter(AppConnect); {
// Package Versions
"@reduxjs/toolkit": "^2.2.3",
"react-redux": "^9.1.1",
"react-router-dom": "^6.26.1"
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all.
I've started migrating from react router V5 to V6 using react-router-dom-v5-compat lib.
I use Redux with Connect HOC and Typescript as well.
So far the migration looks good, components are rendering but I got some Typescript errors when using React element in Route's 'element' property:
<Route path={routes.receipt.path} element={<Receipt /> />
the error:
Property 'isComplete' is missing in type '{}' but required in type 'ReduxProps'.
connect.ts:
receipt.tsx:
index.ts:
export { Receipt } from './connect';
If I use Component={WithdrawalReceipt} I get another TS error as well.
Beta Was this translation helpful? Give feedback.
All reactions