Last active
April 23, 2024 07:01
-
-
Save robinweser/9d99fbddce57cd703cec3701de02d84b 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
// this is exported by "some-package" | |
export default function El({ as: Component = "div", ...props }) { | |
return <Component {...props} /> | |
} |
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 El from "some-package" | |
function Foo(props: { foo: string }) { | |
return <div>{props.foo}</div> | |
} | |
const test = () => [ | |
<El as="div" className="foo" bar="baz" />, | |
<El as={Foo} foo="bar" bar="baz" />, | |
] |
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
export interface PolymorphicProps< | |
T extends keyof JSX.IntrinsicElements | React.ComponentType<any>, | |
> { | |
as: T | |
} | |
type ComponentProps<T> = T extends keyof JSX.IntrinsicElements | |
? JSX.IntrinsicElements[T] | |
: T extends React.ComponentType<infer P> | |
? P | |
: never | |
declare module 'some-package' { | |
export function El< | |
T extends keyof JSX.IntrinsicElements | React.ComponentType<any>, | |
>(props: PolymorphicProps<T> & ComponentProps<T>): JSX.Element | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment