HTML 요소 Props 확장하기

1 minute read
2024-09-04

코드

HTML Props
import React, { PropsWithChildren } from 'react';
 
type H3Props = React.HTMLAttributes<HTMLHeadingElement>;
type ExtendedH3Props = PropsWithChildren<H3Props & {
  customProp?: string;
}>;


사용 시에는


component
function Comp({children, ...props}: ExtendedH3Props) {
  return (
  	<h3 {...props} className={cn(props.className, "...")}>
    	{children}
    </h3>
  )
}