-
[18]"key"는 무엇이며 사용할 때의 이점은 무엇인가?dev/Web 2021. 4. 12. 20:08
key는 고유한 값으로 React가 어떤 항목을 변경, 추가 또는 삭제할지 식별하는 것을 돕는다. key는 엘리먼트에 안정적인 고유성을 부여하기 위해 배열 내부의 엘리먼트에 지정해야 한다.
자식들이 key를 가지고 있다면, React는 key를 통해 기존 트리와 이후 트리의 자식들이 일치하는지 확인한다.
key를 이용해 React는 트리의 변환 작업이 효율적으로 수행되도록 수정할 수 있습니다.
- 데이터 ID를 키로 사용하는 경우가 가장 많다.
- 렌더링된 아이템에 대한 안정적인 ID가 없는 경우, 아이템 인덱스를 키로 사용할 수 있다.
'dev > Web' 카테고리의 다른 글
[17]인라인 조건식이란? (0) 2021.04.12 [16]합성 이벤트(synthetic events)란? (0) 2021.04.12 [15]이벤트 핸들러 또는 콜백에 매개 변수를 전달하는 방법 (0) 2021.04.12 [14]JSX 콜백에서 메서드 또는 이벤트 핸들러를 바인딩하는 방법 (0) 2021.04.12 [13]HTML과 React 이벤트 처리의 차이점 (0) 2021.04.12