제네릭 컴포넌트 선언
type ListType = Array<Vehicle | Animal>;
type Props<T> = {
list: T;
};
const List = <T extends ListType>({list}: Props<T>) => {
return (<FlatList renderItem={(index, item) => (
<View key={index}>
{children}
</View>)} />);
};
사용
export type Vehicle = {
maxSpeed: 400;
minSpeed: 0;
color: string;
maker: string;
}
export type Animal = {
type: 'reptile' | 'primate' | 'birds';
life: number;
}
const dataList: Vehicle[] = {
...
};
const App = () => {
return (
<View>
<List list={dataList} />
</View>
);
};