니꼬쌤 State 강의 최종장!@
컴포넌트가 여러개 있을 때 html select를 이용하여 번갈아 노출시키는 법을 알아보자.
//각각의 스위치 함수를 만들어주고 여기서는 생략
function MinutesToHours()
function KmToMill()
function App() {
const [index, setIndex] = React.useState("0")
const onSelect = (event) => {
setIndex(event.target.value)
}
return (
<div>
<h1 className="h1">Super Converter</h1>
<select value={index} onChange={onSelect}>
<option value="0">Minutes & Hours</option>
<option value="1">Km & Miles</option>
</select>
<hr />
{index === "0" ? <MinutesToHours /> : null}
{index === "1" ? <KmToMill /> : null}
</div>
)
}