Skip to content

Instantly share code, notes, and snippets.

@newerton
Created September 15, 2022 18:13
Show Gist options
  • Save newerton/ce479bdf08821664bbb04c0306bf4817 to your computer and use it in GitHub Desktop.
Save newerton/ce479bdf08821664bbb04c0306bf4817 to your computer and use it in GitHub Desktop.
Apply Interface segregation principle (ISP)
type Props = {
items: Array<Video | LiveStream>
}
const VideoList = ({ items }) => {
return (
<ul>
{items.map(item => {
if ('coverUrl' in item) {
// it's a video
return <Thumbnail coverUrl={item.coverUrl} />
} else {
// it's a live stream
return <Thumbnail coverUrl={item.previewUrl} />
}
})}
</ul>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment