type Item = string | number | undefined
interface IListProps {
items: Item[],
renderItem:(item:Item) => React.ReactNode,
}
const List: React.FC<IListProps> = ({ items, renderItem }) => (
<>
{items.map(renderItem)}
</>
)
interface IButtonProps {
item:string | number | undefined
}
const Button:React.FC<IButtonProps> = ({item}) =>{
return(
<div>{item}</div>
)
}
interface ICalcProps {
result: number
}
const Calculator: React.FC<ICalcProps> = ({ result }) => {
return (
<>
<List items={[1,2,3,4,5]} renderItem={Button}/>
<div>{result}</div>
</>
)
}
вот сюда закинь http://www.typescriptlang.org/play/
Обсуждают сегодня