함수컴포넌트에서 라이프사이클을 사용하게 해줌
훅 안에서 useState()
로 선언할 때 스코프 내에서 바로 해줘야함
컴포넌트의 속성
부모로부터 전달받아 사용(자식에서 ${props."key"
}로 사용)
객체형태임(key:value)
컴포넌트를 재활용시 활용도를 높임
주어진 것? 초기화된 것?(State와 비교)
// 부모
<Comment username="saengmotmi" text="안녕하세요" />
// 자식
fucntion Comment(props) {
return <li>{props.username}" {props.text}</li>
}
// props. 생략
fucntion Comment({username, text}) {
return <li>{username}" {text}</li>
}
변경되는 상태(변경될 값만 State로 관리)
화면에 보여줄 컴포넌트의 UI정보
function Mentor ({ name, position }) {
const [balance, setBalance] = useState(100000); // 잔고
const [health, setHealth] = useState(70); // 건강
const mineWon = () => {
setBalance(balance + 100000);
};
const exercies = () => {
return (
<div>
</div>
);