React & TypeScript/React
[React] Props란 무엇인가?
yoonjong Park
2021. 1. 27. 07:30
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
function App() {
return (
<div>
<Welcome name="Sara" />
<Welcome name="Cahal" />
<Welcome name="Edite" />
</div>
);
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
App function이 있는 이유는 return에서 여러 개의 복합적으로 구성된 Component를 한번에 ReactDOM.render에 보내기 위해서이다.
정확히는 index.html에 있는 div class=root 에 보내기 위해서이다.
props는 객체 생성 시에 지정되는 value를 받아서 처리하기 위한 react에만 있는 유니크한 정의이다. (위에서는 Welcome 을 생성 시에 "Sara", "Cahal", "Edite" 값을 받아주는 역할을 하고 있다.
함수형과 클래스 형은 처리하는 방식이 다르다.