If you are trying to pass an array of numbers (extrapolated from data={1,2,3}). then you just need to pass number as the generic type to your Props. Theres more mapping you need to do to get the types to match correctly.
export interface ListProps<T = unknown> {
data: T[];
render: (item: T) => React.ReactElement;
}
export const GenericListItems = <T extends any>(): React.FC<ListProps<T>> => ({
data,
render
}): any => {
return data.map(render);
};
Strongly typing your list would look like
const StringList = GenericListItems<string>();
const NumberList = GenericListItems<number>();
interface JsxClass<P, S> extends React.Component<P, S> {
render(): React.ReactElement<P>[];
}
interface GenericComponentType<P, S> {
new (props: P): JsxClass<P, S>;
}
interface ListProps<T> {
data: T[];
render: (value: T) => any;
}
class List<T> extends React.Component<ListProps<T>, {}> {
render(): React.ReactElement<any>[] {
return this.props.data.map(this.props.render);
}
}
Strongly typing your list would look like
const NumberList: GenericComponentType<ListProps<number>, {}> = List;
const StringList: GenericComponentType<ListProps<string>, {}> = List;
Both of these (Component Class or Functional Component) instances can be used the same way.
<NumberList
data={[1, 2, 3]}
render={value => <div>{value + 2}</div>}
/>
<StringList
data={["I", "Render", "Strings"]}
render={value => <div>{value}</div>}
/>
const List: React.FC<Props<MyTypeHere>>Cannot find name 'MyTypeHere'.Datato your interface. You need to pass whatever that is through in the component type definition