Skip to content

Instantly share code, notes, and snippets.

@ryanditjia
Created July 15, 2019 07:13
Show Gist options
  • Select an option

  • Save ryanditjia/b2ee5ba40bca8d653373657aaaebad3d to your computer and use it in GitHub Desktop.

Select an option

Save ryanditjia/b2ee5ba40bca8d653373657aaaebad3d to your computer and use it in GitHub Desktop.
Dynamic tagname React
import React from 'react'
type Props = React.HTMLAttributes<HTMLElement> & {
as?: 'div' | 'article' | 'section'
}
export const Card: React.FC<Props> = ({
children,
as: Component = 'div',
className,
...restProps
}) => {
return (
<Component
className={className + ' bg-white p-4 rounded-lg shadow'}
{...restProps}
>
{children}
</Component>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment