HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🐣
프론트엔드 데브코스 4기 교육생
/
🌻
나유리팀
/
☕
커피챗
/
타입스크립트를 이용하여 HTML Element를 표현하는 방법이 궁금합니다..!

타입스크립트를 이용하여 HTML Element를 표현하는 방법이 궁금합니다..!

이번 리액트 강의를 타입스크립트로 마이그레이션하면서 듣고 있는데,
유리멘토님은 어떻게 HTML Props를 타입스크립트로 표현하는지 궁금합니다!
HTMLAttributes 를 이용하여 표현하였을때 , props로 div 태그와 관련된 프로퍼티들을 마구마구 넘겨줘도 되는걸까요?!
...props 를 사용하고 싶은데, 어떻게 하면 props의 타입을 현명하게 받을 수 있을 지 고민입니다 🤔
또한, Partial<HeaderProps>를 통해서 Prop을 한번 더 걸러주는 작업이 필요할까요?

HTMLHeadingElement 이용하기!!!
질문자
날짜
Aug 18, 2023
상태
답변완료
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> }