Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MauricioRobayo/2511350833cce666ed8e343a8ddd5f21 to your computer and use it in GitHub Desktop.
Save MauricioRobayo/2511350833cce666ed8e343a8ddd5f21 to your computer and use it in GitHub Desktop.
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