Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sometimes createElement makes more sense
import { ComponentType, createElement, CSSProperties } from 'react'
interface HasKey {
key: string
}
type HomogenousListProps<T> = {
as?: 'ol' | 'ul'
component: ComponentType<T>
items?: Array<T>
style?: CSSProperties
}
function HomogenousList<T extends HasKey>({
as = 'ul',
component,
items = [],
style,
}: HomogenousListProps<T>) {
return createElement(
as,
{ style },
items.map((item: T) => createElement(component, item))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment