반응형
import React, { Component } from 'react';
type MonitoringType = 'T' | 'S';
interface Props {
monitoringType: MonitoringType;
}
class MonitoringLabel extends Component<Props> {
getLabel = (): string => {
return this.props.monitoringType === 'T' ? 'Activity Name' : 'Monitoring Name';
};
render() {
return (
<div>
<label>{this.getLabel()}</label>
</div>
);
}
}
export default MonitoringLabel;
import React, { Component } from 'react';
type MonitoringType = 'T' | 'S';
interface Props {
monitoringType: MonitoringType;
}
class MonitoringLabel extends Component<Props> {
getLabel = (): string => {
const { monitoringType } = this.props;
switch (monitoringType) {
case 'T':
return 'Activity Name';
case 'S':
return 'Monitoring Name';
default:
return 'Unknown';
}
};
render() {
return (
<div>
<label>{this.getLabel()}</label>
</div>
);
}
}
export default MonitoringLabel;
반응형
'React' 카테고리의 다른 글
유효한 Date 객체인지 검사하는 유틸리티 함수 (0) | 2025.06.11 |
---|---|
React 17 + TypeScript 환경의 클래스 컴포넌트에서 hh24:mi 형식(예: 13:32)의 값을 입력받아 유효성 검증하는 (0) | 2025.06.11 |
하단 그리드(BottomGrid.tsx)에서 hide 사용 예제 (0) | 2025.06.10 |
Failed prop type: invaild prop value[0] of type String supplied to DataRangePicker, expcted instance of 'Date' 오류 (0) | 2025.06.10 |
React 17 + TypeScript에서 onLoad 이벤트 구현 예제 (0) | 2025.06.09 |