
์ฝ๋๊ฐ ๊ฐ๋จํ ๊ฒ์ด ํน์ง, Component๋ฅผ ํจ์ ์ทจ๊ธ
function Welcome(props){ return <h1>์๋ , {props.name} </h1>; };
React.Component๋ฅผ ์์๋ฐ์์ Component๋ฅผ ๋ง๋๋ ๊ฒ
Class Welcome extends React.Component { render() { return <h1> ์๋ , {this.props.name}</h1>; } }
ํญ์ ๋๋ฌธ์๋ก ์์ํด์ผ ํ๋ค!
์๋ฌธ์๋ก ์์ํ๋ฉด domc ํ๊ทธ๋ก ์ธ์ํ๊ธฐ ๋๋ฌธconst element = <div/>
๋ณต์กํ ํ๋ฉด์ ์ฌ๋ฌ ๊ฐ์ ์ปดํฌ๋ํธ๋ก ๋๋์ด์ ํ๋ฉด ๊ตฌํ ๊ฐ๋ฅ
ํ์ ์ปดํฌ๋ํธ๋ฅผ ์์ ์ปดํฌ๋ํธ๊ฐ ํฌํจํ์ฌ ์์ฑ๋๋ ๊ฒ
ํฐ ์ปดํฌ๋ํธ์์ ์ผ๋ถ๋ฅผ ์ถ์ถํ์ฌ, ์์ ์ปดํฌ๋ํธ๋ฅผ ์์ฑํ์ฌ ์ฌ์ฌ์ฉ์ฑ์ ๋์
//Comment(ํ์ ์ปดํฌ๋ํธ)
const styles= {
wrapper: {
margin:8,
padding:8,
display:"flex",
flexDirection: "row",
border: "1px solid gray",
borderRadius: 16
},
imageContainer:{},
image: {
width: 50,
height: 50,
borderRadius: 25,
},
contentContainer:{
marginLeft:8,
display: "flex",
flexDirection: "column",
justifyContent: "center",
},
nameText: {
color: "black",
fontSize: 16,
fontWeight: "bold",
},
commentText: {
color: "black",
fontSize: 16,
},
};
function Comment(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>
);
}
export default Comment;
//์์ ์ปดํฌ๋ํธ
import Comment from "./Comment";
const comments = [
{
name: "์ด๋ฏผํ",
comment:"ํ์ดํ์ด",
},
{
name: "๋๊ตฌ๊ฒ",
comment: "๋ฆฌ์กํธ ํใ
",
},
{
name: "ํ๋๋ฌ",
comment:"ํํํ ์ธ์ ..",
},
];
function CommentList(props){
return(
<div>
{comments.map((comment) => {
return (
<Comment name={comment.name} comment={comment.comment}/>
);
})}
</div>
);
}
export defualt CommentList;