Skip to content

Instantly share code, notes, and snippets.

View davegomez's full-sized avatar
🏠
Working from home

David Gomez davegomez

🏠
Working from home
View GitHub Profile
@davegomez
davegomez / Box.tsx
Created October 7, 2024 18:28 — forked from kripod/Box.tsx
Superseded by https://www.kripod.dev/blog/behind-the-as-prop-polymorphism-done-well/ – Polymorphic `as` prop for React components with TypeScript
import React from 'react';
// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts
type PropsOf<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
E extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>
> = JSX.LibraryManagedAttributes<E, React.ComponentPropsWithRef<E>>;
export interface BoxOwnProps<E extends React.ElementType = React.ElementType> {
as?: E;