component 사용의 장점
- 재사용 가능
- 코드를 더 깔끔하게 만들어줌
모든 react component는 그들의 Props에 관해서는 Pure 함수 같은 역할을 해야한다
➡ 모든 react component는 Props를 직접 바꿀수 없고, 같은 Props에 대해서는 항상 같은 결과를 보여줘야한다.
- component
function Comment(props){ <!-- Comment 라는 component를 생성하였고 그 안에 props를 넣음-->
return(
<div style={styles.wrapper}>
<div style={styles.imageContainer}>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" style={styles.image} />
</div>
<div style={styles.contentContainer}>
<span style={styles.nameText}>{props.name}</span>
<span style={styles.commentText}>{props.comment}</span>
</div>
</div>
);
}
- props
const comments =[
{
name : "1번",
comment: "으아아아아아아아아아",
},
{
name : "2번",
comment: "호오오아ㅗ아와와와아이",
},
{
name : "3번 ",
comment: "으이이이이이이이이이이이",
},
];
constructor(props){
super(props);
this.state={};
}