composition&inheritance in React
관계 포함 (containment)
구성 요소 가 하위 구성 요소 가 무엇 인지 모 르 면 용기 구성 요소 에서 흔히 볼 수 있 습 니 다. props. children 으로 하위 구성 요 소 를 전달 하 는 것 이 좋 습 니 다.
function BoxContainer = () =>{
return(
{props.children}
);
}
function ContentInsideboxContainer = () =>{
return(
Hello!
Something inside here!
)
}
특례 관계 (specialization)
I, e, welcome dialog 는 dialog 의 특례 이다.
function Dialog = () =>{
return(
{props.title}
{props.message}
{props.children}
);
}
function WelcomeDialog = () =>{
return(
);
}
class 에 도 사용 할 수 있 습 니 다.
i.e.
function Dialog = () =>{
return(
{props.title}
{props.message}
{props.children}
);
}
class WelcomeDialog extends[React.Component](http://react.component/){
consturctor(props){
super(props);
this.state={
login: ‘’,
}
}
handleChange = (e) => {this.setState({login:e.target.value});}
render(){
return(
);
}}