The approach
I'm trying to get my head around Typescript and React Router. I've been struggling...
I currently get the error :
Property 'params' does not exist on type 'RouteComponentProps<{}, StaticContext, any>'.ts(2339)"`
import React from "react";
import { RouteComponentProps } from "react-router-dom";
const TopicDetail = ({ match }: { match: RouteComponentProps }) => {
return (
<div>
<h3>{match.params.topicId}</h3>
~~~~~~
</div>
);
};
export default TopicDetail;
Look ma, no errors!
I can get rid of the errors by defining my own interface, but I somehow feel it's the wrong way to do it:
import React from "react";
interface Props {
params: any;
}
const TopicDetail = ({ match }: { match: Props }) => {
return (
<div>
<h3>{match.params.topicId}</h3>
</div>
);
};
export default TopicDetail;