Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vladimir-ivanov/25aacf7fe502fef27cd5e3bf2ebe4402 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/25aacf7fe502fef27cd5e3bf2ebe4402 to your computer and use it in GitHub Desktop.
Box.tsx
type Records<Keys extends keyof JSX.IntrinsicElements = keyof JSX.IntrinsicElements> = {
[P in Keys]: CSSProperties & JSX.IntrinsicElements[P] & { tag: P; };
}[Keys];
const Box: FC<Records> = ({tag, children, ...rest}): JSX.Element => {
const {styles, attributes} = splitProps(rest);
const Tag = tag as string;
return <Tag style={styles} {...attributes}>{children}</Tag>
}
const Test: FC = () => (
<Box tag='button' type="submit" onSubmit={console.warn}/>
)
@vladimir-ivanov
Copy link
Author

couples tag with attributes to match e.g. and not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment