Let's say I have a class like this:
class PeopleByTag extends React.Component<RouteComponentProps<{ tag: string }>
I need to do something in my constructor, in this example fetch data, but to do that I need to declare a props parameter, but if I don't specify the type it will become any:
constructor(props) {
super(props); // props is any
this.loadData();
}
On the other hand, if I redeclare the type the code gets very ugly:
constructor(props: Readonly<{
children?: React.ReactNode;
}> & Readonly<RouteComponentProps<{
tag: string;
}, StaticContext, any>>) {
super(props);
this.loadData();
}
Is there a way to automatically infer the props type from the class extension while also being able to write a constructor?
I also don't want to use the deprecated lifecycle hooks (i.e. ComponentWillMount).