Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

new_bird-hyun

03. 리액트 list 랜더링과 key 값 설정하기 본문

코딩 공부

03. 리액트 list 랜더링과 key 값 설정하기

새혀니 2023. 5. 31. 00:20
import React from "react";

const students = [
    {
        id:1,
        name:"hyeji",
    },
    {
        id:2,
        name:"sehyun",
    },
    {
        id:3,
        name:"chunghwan",
    },
    {
        id:4,
        name:"sunyoung",
    },
];

function AttendanceBook(props) {
    return(
        <ul>
            {students.map((student) => {
                return <li key={student.id}>{student.name}</li>
            })}
        </ul>
    );
}

export default AttendanceBook;

리스트를 랜더링 할때는 map을 사용하며 리스트에는 반드시 id 등을 통한 key 값이 포함 되어야 한다.