이번 리액트 강의를 타입스크립트로 마이그레이션하면서 듣고 있는데,
유리멘토님은 어떻게 HTML Props를 타입스크립트로 표현하는지 궁금합니다!
interface HeaderProps extends HTMLAttributes<HTMLDivElement>{ children: ReactNode, level: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' underline?: boolean, color?: CSSProperties['color'] } const Header = ({children ,level = 'h1', underline, color, ...props} : HeaderProps) => { const HeaderTag = level const fontStyle = { textDecoration: underline ? 'underline' : undefined, color } return <HeaderTag style={{...props.style, ...fontStyle}} {...props}>{children}</HeaderTag> }
HTMLAttributes
를 이용하여 표현하였을때 , props로 div
태그와 관련된 프로퍼티들을 마구마구 넘겨줘도 되는걸까요?!...props
를 사용하고 싶은데, 어떻게 하면 props의 타입을 현명하게 받을 수 있을 지 고민입니다 🤔또한,
Partial<HeaderProps>
를 통해서 Prop을 한번 더 걸러주는 작업이 필요할까요? HTMLHeadingElement
이용하기!!!