1. ํด๋ ๊ตฌ์กฐ
2. Comment.jsx
import React from "react";
const styles = {
wrapper: {
margin: 8,
padding: 8,
display: "flex",
flexDirection: "row",
border: "1px solid grey",
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,
}
}
const Comment = (props) => {
return (
<div style={styles.wrapper}>
<div style={styles.imageContainer}>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png"
alt=""
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;
๊ธธ์ด ๋ณด์ด๋๋ฐ, Style์ CSS ์ฉ์ด์ด์ ๊ทธ๋ฆฌ ์ค์ํ ๋ถ๋ถ์ ์๋๋ค. ์ ํ์ธํด์ผํ ๋ถ๋ถ์, ํด๋น Comment ์ปดํฌ๋ํธ๋ props์์ ์ด๋ฆ๊ณผ ๋๊ธ์ ๋ฐ์์ ๋ฟ๋ฆฐ๋ค๋ ๊ฒ์ด๋ค.
2. CommentList.jsx
import React from "react";
import Comment from "./Comment";
const comments = [
{
name: "์ ์๋ฏผ",
comment: "๋๊น์ง ๊ฐ๋ฉด ๋ด๊ฐ ๋ค ์ด๊ฒจ"
},
{
name: "์ด๋ฏผํ",
comment: "๋ณด๊ณ ์ถ๋ค ์น๊ตฌ๋ค์"
},
{
name: "์ฐจ์ฐจ",
comment: "๋ค ํจ๊ป, ์ฐจ์ฐจ์ฐจ"
}
];
const CommentList = (props) => {
return (
<div>
{comments.map((comment) => {
return (
<Comment name={comment.name} comment={comment.comment}/>
);
})}
</div>
)
}
export default CommentList;
์ผ๋จ ์ฌ์ฉ์๋ก๋ถํฐ ๊ฐ์ ๋ฐ๋ ๊ฒ์ ๋ฐ๋ก ํ์ง ์์๊ณ , ์ ์ ์ธ ๋ฐฐ์ด์ ๊ฐ๋ค์ ๋ฐ์์ ๋ฐฐ์ด์ ํฌ๊ธฐ๋งํผ Comment ์ปดํฌ๋ํธ๋ฅผ ๋ฐ๋ณตํ์ฌ ๊ฐ์ ๋ณด๋ด๊ณ ์๋ค. ์ด๋ ์ฌ์ฉํ ๊ฒ์ด map ํจ์์ธ๋ฐ, map ํจ์๋ ๋ฐฐ์ด์ ์์ ํ๋ํ๋๋ฅผ ์ํํ๋ค๋ ํน์ง์ด ์๋ค.
3. ์ต์๋จ index.jsx
ReactDOM.render(
<React.StrictMode>
<CommentList/>
</React.StrictMode>,
document.getElementById('root')
)
์ด๋ ๊ฒ ๋ฐ๊ฟ์ค๋ค.
4. ์์ฐ ํ๋ฉด
0