Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 이벤트루프
- getServerSideProps
- react
- CSS
- 브루트포스
- 자바스크립트엔진
- flexible box
- getInitialProps
- 매크로태스크큐
- 리팩터링2판
- NextImage
- nestjs
- resource owner
- 마이크로태스크큐
- 브라우저동작
- 개발도서추천
- BOJ
- nextjs
- 콜스택
- NextImageSpan
- backend
- 자바스크립트런타임
- prevProps
- Next이미지
- componentDidUpdate
- 브라우저동작원리
- access token
- NeXT
- 판교브루클린
- resource server
Archives
- Today
- Total
imgyuzzzang
[Warning] Each child in a list should have a unique "key" prop : map function 사용 시 key값 필요 본문
computer science/에러로그
[Warning] Each child in a list should have a unique "key" prop : map function 사용 시 key값 필요
imgyuzzzang 2021. 3. 2. 18:49React.js: List의 map 함수를 사용하여 렌더링할 때, key prop을 추가해야한다.
render(){
let list = this.state.fileList ?
this.state.fileList.map(file =>
<a>{file.dest}</a>) : ""
return( <div> {list} </div> )
}
예를 들어 다음과 같이 fileList의 element를 이용하여 return값을 띄우려고 할 때,
기존에 알고 있던 map 사용하듯이 Array.map(element => <div>{element.name}</div>) 이 아닌,
element의 고유 식별 값이 list의 각 element에 key값으로 포함되어야함.
위 예시를 다음과 같이 바꾸어 쓴다. Array.map(element => <div key={element.id}>{element.name}</div>)
즉, 코드에서도 key 값을 다음과 같이 포함할 수 있다!! :)
render(){
let list = this.state.fileList ?
this.state.fileList.map(file =>
<a key={file.id}>{file.dest}</a>) : ""
return( <div> {list} </div> )
}
'computer science > 에러로그' 카테고리의 다른 글
[NEXT JS] getServerSideProps는 Date 객체를 허락하지 않아,, (1) | 2022.11.22 |
---|
Comments