Notice
Recent Posts
Recent Comments
«   2026/04   »
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
Tags
more
Archives
Today
Total
관리 메뉴

Chimy's Program

Warning: Each child in a list should have a unique "key" prop. 본문

error

Warning: Each child in a list should have a unique "key" prop.

chimy 2021. 1. 16. 22:07

Warning: Each child in a list should have a unique "key" prop.

 

JavaScript 라이브러리 중 하나인 React를 사용하다 발생한 에러로

JavaScript에서 배열 값을 하나씩 꺼내어 리턴할 때 react가 항목을 안정적으로 식별할 수 있도록

속성에 key값을 추가하여 반환해주어야 한다

 

 

참고1.

ko.reactjs.org/docs/lists-and-keys.html#keys-must-only-be-unique-among-siblings

 

리스트와 Key – React

A JavaScript library for building user interfaces

ko.reactjs.org

 

 

해결1.

하지만 나는 위와 같은 코드로 배열에서 인자를 꺼낼 때 고유의 key값을 주어 인식이 가능하도록 하였기 때문에 

어느 부분에서 에러가 발생했는지 찾는데 애를 먹었다

 

 

위와 같이 배열의 길이를 반환하는 엘리먼트에도 키값을 부여하니 에러가 사라졌다

 

 

Comments