Last active
August 21, 2020 13:29
-
-
Save okovpashko/a88e356bffd9e3977df2fa42709f8ed4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React, {type ComponentType, type AbstractComponent} from 'react'; | |
//////////////////////////// | |
// A generic list component | |
//////////////////////////// | |
type ListProps<P> = {| | |
component: ComponentType<P>, | |
items: Array<P>, | |
|}; | |
const List = <P>(props: ListProps<P>) => { | |
const {component: Component, items} = props; | |
return items.map(item => ( | |
<Component {...item}/> | |
)); | |
}; | |
//////////////// | |
// A list item | |
//////////////// | |
type CarProps = {| | |
model: string, | |
|}; | |
const Car = (props: CarProps) => { | |
return <div>props.model</div>; | |
}; | |
/////////////////// | |
// The concrete list | |
/////////////////// | |
type CarsListProps = { | |
cars: Array<CarProps>, | |
}; | |
const CarsList = (props: CarsListProps) => { | |
return <List component={Car} items={props.cars}/> | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment