🌱 Typing a dynamic tag in React with TypeScript

Source
interface CompProps {
  tag: keyof JSX.IntrinsicElements
}

const MyComponent: React.FunctionComponent<CompProps & React.HTMLAttributes<HTMLOrSVGElement>> = ({
  tag: Wrapper = 'div',
  children,
  ...rest
}) => {
  return <Wrapper {...rest}>{children}</Wrapper>
}
Made by Brandon . If you find this project useful you can donate.