3 ms·
I'd write it like this const gridComponent = { image: GridImage, video: GridVideo, copy: GridCopy } const Grid = (gridItems) => (
by methyl 5y ago
I'd write it like this
const gridComponent = {
image: GridImage,
video: GridVideo,
copy: GridCopy
}
const Grid = (gridItems) => (
<Grid>
{gridItems.map(item => {
const GridComponent = gridComponent[item._type]
return GridComponent ? <GridComponent {...item} key={item._key} /> : null
}}
</Grid>
)}
- 9wzYQbTYsAIc 5y agoThat’s definitely representative of the compactness that is possible with modern JSX.