function App() {
return (
<div>
<Header />
<Content />
<Footer />
</div>
);
}일반적 컴포넌트를 어떻게 특수하게 사용할 것인가?
ex) 버튼 => 로그인 버튼 / 회원가입 버튼
function UserWelcome({ username }) {
return <Welcome text={`Hello, ${username}!`} />;
}
function GuestWelcome() {
return <Welcome text="Welcome, Guest!" />;
}
function Welcome({ text }) {
return <h1>{text}</h1>;
}
React Component의 property, 매개변수와 같은 역할
컴포넌트에 전달할 정보를 담고 있는 자바스크립트 객체
Props는 읽기 전용, 값을 직접 바꿀 수 없다.
비구조화 할당 = 구조 분해 문법 을 사용하여 props를 전달할 수 있다
// Without destructuring
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
// With destructuring
function Welcome({ name }) {
return <h1>Hello, {name}</h1>;
}