반응형

ul-li 태그 반복하여 출력하기
function H_Book() {
const students = [
{
id: 1,
name: "Inje",
},
{
id: 2,
name: "Steve",
},
{
id: 3,
name: "Bill",
},
{
id: 4,
name: "Jeff",
},
];
// 변수정의
const [student, setStudent] = useState(students);
return (
<div>
<ul class="list-group">
{/* 반복문 : 여기서 돌리면 됨 */}
{student.map((value, index) => {
return (
<li class="list-group-item">{value.name}</li>
);
})}
</ul>
</div>
);
}
export default H_Book;

반응형
'React > 실습' 카테고리의 다른 글
삼항연산자를 이용한 실습 (0) | 2023.08.31 |
---|---|
조건문을 활용한 예제 (0) | 2023.08.31 |
반복문을 활용한 예제 (0) | 2023.08.31 |
useState 이용 4가지 변수 넣기 (0) | 2023.08.31 |
useState 함수를 이용한 Comment 출력 (0) | 2023.08.31 |