Created
March 14, 2023 14:06
-
-
Save MauricioRobayo/2511350833cce666ed8e343a8ddd5f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ComponentPropsWithoutRef, ElementType, ReactNode } from "react"; | |
import "./styles.css"; | |
interface Component1Props<T extends ElementType = "div"> { | |
as?: T; | |
children: ReactNode; | |
} | |
type Props<T extends ElementType> = Component1Props<T> & | |
Omit<ComponentPropsWithoutRef<T>, keyof Component1Props<T>>; | |
function Component1<T extends ElementType>({ children, as }: Props<T>) { | |
const Component = as ?? "div"; | |
return <Component>{children}</Component>; | |
} | |
export default function App() { | |
return ( | |
<div className="App"> | |
<Component1 as="button" onClick={() => null}> | |
Hello | |
</Component1> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment