3항 연산자, if문 두가지 방법이 있음
3항 연산자 사용법
.map(id => {
return this.props.schema.collectionName.length < 0 ?
<Expandable>
<ObjectDisplay
key={id}
parentDocumentId={id}
schema={schema[this.props.schema.collectionName]}
value={this.props.collection.documents[id]}
/>
</Expandable>
:
<h1>hejsan</h1>
}
if 문 사용법
.map(id => {
if(this.props.schema.collectionName.length < 0)
return <Expandable>
<ObjectDisplay
key={id}
parentDocumentId={id}
schema={schema[this.props.schema.collectionName]}
value={this.props.collection.documents[id]}
/>
</Expandable>
return <h1>hejsan</h1>
}
출처 : https://stackoverflow.com/questions/44969877/if-condition-inside-of-map-react
If condition inside of map() React
I have a map()function that needs to display views based on a condition. I've looked at the React documentation on how to write conditions and this is how you can write a condition: {if (loggedIn)...
stackoverflow.com
'FrontEnd > React' 카테고리의 다른 글
[React] 글자 수 검사 (0) | 2022.01.11 |
---|---|
[React] 컴포넌트 반복(map()과 key) (0) | 2022.01.11 |
[React] setState 다양하게 적용하기 (0) | 2022.01.05 |
[React] map의 마지막 순서 구하기 (0) | 2022.01.04 |
[React] 동적 키 이름을 가진 setState () (0) | 2021.12.28 |