I have been working with React JS & Flow for quite a bit and now, recently switching over to typescript. I am not sure why typescript complains on the Stateless Component Definition.
Source
interface Test2Prop {
names : string[];
}
const TestComponent: SFC<TestProp> = (props: TestProp) => {
return (
props.name.map((val, idx) => <h3 key={idx}>{`APPENDING-${val}`}</h3>)
);
}
Error
[ts]
Type '(props: TestProp) => Element[]' is not assignable to type 'FunctionComponent<TestProp>'.
Type 'Element[]' is not assignable to type 'ReactElement<any>'.
Property 'type' is missing in type 'Element[]'. [2322]
And I am not sure why using React.Fragment makes the error go away.
interface Test2Prop {
names : string[];
}
const Tests : React.SFC<Test2Prop> = (props : Test2Prop) => {
return (
<React.Fragment>
{ props.names.map(name => <h1>{name}</h1>) }
</React.Fragment>
);
}
I don't want to use React.Fragment as that is not a solution but a hack as per my understanding.