💡 문제점: Warning: Each child in a list should have a unique "key" prop.
- key는 변하지 않고, 유일해야 함
- 가장 먼저 index가 떠오르지만, React(+React Native)에서는 index로 key값을 주는 것을 지양 -> 항목들이 재배열(삽입 및 삭제)될 경우 비효율적으로 동작하기 때문
💡 해결방법
- 해결방법 1: key를 item 값으로 세팅 -> item 중에 같은 값이 있다면 key가 독립적이지 않음
{ text: enteredGoalText, id: Math.random().toString() },
keyExtractor={(item) => {
return item.text;
}}
- 해결방법 2: id 속성을 데이터에 추가해주거나 데이터 일부에 해시를 적용하여 key 세팅 (권장)
{ text: enteredGoalText, id: Math.random().toString() },
keyExtractor={(item) => {
return item.id;
}}