Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created May 28, 2021 16:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleshevlin/a5f8c8a8b3857ed61de3b21b2889411a to your computer and use it in GitHub Desktop.
Save kyleshevlin/a5f8c8a8b3857ed61de3b21b2889411a to your computer and use it in GitHub Desktop.
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