I am trying out Typescript with react (never worked before). I Solved a problem but I am not sure if this is the proper way to do it.
So my route in react looks like this
<Route exact path='/show/:id' component={ShowIssues} />
And my component solved is looking like this
import React from "react";
import { RouteProps } from "react-router-dom";
interface RouteInfo extends RouteProps {
params: {
id: string;
};
}
const ShowIssues = ({ match }: { match: RouteInfo }) => {
const { params }: { params: { id: string } } = match;
const { id }: { id: string } = params;
return <div>time to show the issue {id}</div>;
};
export default ShowIssues;
Is correct solved in the props this match? Surprisingly I've not found almost anything regarding function components ( and hooks are coming, so I guess makes sense to raise this doubt).
My other doubt goes for const { params }: { params: { id: string } } = match; is there a way I can reuse the RouteInfo so I don't have to type it twice?
Thanks!