class component의 타입 선언

With·2021년 9월 9일
0
type State = {
  first: number,
  second: number,
  value: string,
  result: string
}


class ComponentName extends React.Component<{}, State> { 
	//  .. 중략
} 

클래스 컴포넌트의 React.Component의 Generic에는 2개를 넣을 수 있는데, 첫번째 자리는 Props에 대한 Type Alias (또는 interface), 두번째 자리는 State에 대한 Type Alias가 들어간다.

profile
주니어 프론트엔드 개발자 입니다.

0개의 댓글