In this simple component, I pass in MyProps which looks like this:
interface MyProps {
profiles: IProfile[]
}
interface IProfile {
name: string;
avatar_url: string;
company: string;
}
My component defines props as MyProp, but the Typescript compiler complains that this.state.profiles does not exist on type Readonly<{}>:
class App extends React.Component<MyProps> {
constructor(props: MyProps) {
super(props);
this.state = { profiles: props.profiles };
}
public render() {
return (<div>//ERROR HERE
{this.state.profiles.map((profile: IProfile) => <Card {...profile} />)}
</div>);
}
};
If I set the second field to any or MyProps it works. Do I always need to define the first 2 params of the React.Component?
class App extends React.Component<MyProps,MyProps>