Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- owlcarousel
- 정적객체
- fontawesome
- 그누보드반응형
- vscode git clone
- 이미지반응형
- slickslider
- 동적객체
- npm start
- 플러그인
- Git clone
- XEIcon
- react npm install
- git lab clone
- window 정책변경
- package.json
- googleicon
- maxwidth
- 웹아이콘
- minwidth
- legacy-peer
- node설치
- node 오류
- npm install
- npm install 문제
- 단어단위로떨어지기
- 아이콘사용법
- MediaQuery
- 의존성문제
- 글자들여쓰기
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
🟦 [React] 삼항 연산자 사용법 본문
728x90
태그 안에서 조건식을 넣어서 구별하고 싶을 때 삼항 연산자 사용!
<tr>
{
activeTab === 0 ?
(<th>1</th>) :
(<th>2</th>)
}
</tr>
이러면 activeTab = 0 일때 th에 1이 표시되고 아닐때 2가 표시 된다.
thead th 탭 구별해서 꾸리기
Tab.jsx 👇
const tabThKey = Object.keys(tabTh);
return(
생략-
<thead>
<tr>
{activeTab == tabName.length - 1
? tabTh[tabThKey[1]].map((th, index) => (
<th key={index}>{th}</th>
))
: tabTh[tabThKey[0]].map((th, index)=> (
<th key={index}>{th}</th>
))
}
</tr>
</thead>
생략-
)
tabdata.js 👇
const tabTh = {
default: [ "경로", "수정 파일", "상세", "URL", "특이 사항", "비고 (주석)", "요청자" ],
metapay: [ "구분", "화면명", "상세", "URL", "수정 사항", "요청자"]
}
항상 태그 한 개만 반환하다 보니 또 실수함
=> ( ) 안에는 꼭 한개의 태그로 묶어줘야한다!!!
🚫 에러 내용 🚫
Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?

<tbody>
{tabData[tabDataKey[index]].map((data, dataIndex) => (
<tr key={dataIndex}>
{
activeTab == tabName.length - 1 ?
(
<>
<td>2번째</td>
</>
):(
<>
<td>{data.section}</td>
<td>
{data.modifyFiles?.map((fileData, index) => (
<div key={index}>
<strong>[ {fileData.type} ]</strong><br/>
{fileData.files.join("<br/>")}
<br/><br/>
</div>
))}
</td>
<td><a href={data.image}></a></td>
<td>
{(typeof data.link === "string" // 문자열인지 구분하여 true면 배열로 반환
? [data.link]
: Array.isArray(data.link) // 배열인지 구분하여 true면 그대로 반환
? data.link
: Object.values(data.link) // 문자열과 배열이 아니면(객체라고 간주) 값을 배열로 변환
).map((link, index) => (
<a key={index} href={link}>{link}</a>
))}
{/*
Array.isArray( data ) => data가 배열(array)인지 확인
Object.values( data ) => data(객체)의 값을 배열로 반환
Object.keys( data ) => data(객체)의 key값을 배열로 반환
Object.entries( data ) => data(객체)의 키-값 쌍 -> key, value를 배열로 반환
Object.fromEntries( data ) => data(배열)를 객체로 변환
*/}
</td>
<td>{data.notice}</td>
<td>
{(typeof data.annotation == "string"
? [data.annotation]
: Array.isArray(data.annotation)
? data.annotation
: Object.values(data.annotation)
).map((annotation, index) => (
<div key={index}>{annotation}</div>
))}
</td>
<td>{data.requestor}</td>
</>
)
}
</tr>
))}
</tbody>728x90
'개발 > 🟦 React' 카테고리의 다른 글
| 🟦 [React] 텍스트 불러올 때 <br /> 사용하기 => <React.Fragment> 이용 (0) | 2025.03.20 |
|---|---|
| 🟦 [React] 배열 반환할 때, 타입이 달라도 무조건적으로 배열 가져오기 (0) | 2025.03.19 |
| 🟦 [React] 중첩된 객체와 배열 구조 => 가지고 오고 싶은 값 사용하기 (0) | 2025.03.18 |
| 🟦 [React] onclick={함수()}, onclick={() => 함수()} 차이점 (0) | 2025.03.18 |
| 🟦 [React] 모달 창 띄우기2_코드 재사용화, 컴포넌트화 시키기 (0) | 2025.03.17 |
Comments
