🚪 ESLint 에러로 번역하자면 삼항 표현식을 중첩하지 마십시오.

관리자 혹은 본인만 삭제할 수 있는 버튼을 만드는 과정입니다.

 

userId를 받아와서 'admin'이면  버튼을 생성하고 아니면 해당 게시물의 ID와 비교해서 일치하면 버튼을 생성한다.

actions={
/* eslint-disable-next-line no-nested-ternary */
(userId === 'admin') ? this.buttonCreate(props) :
(props.userID === userId) ?
this.buttonCreate(props)
: ''}
buttonCreate = (props) => {
return [<Button.Remove onClick={() => this.replyDelete(props)}> {translate('delete')}</Button.Remove>];
}

📌 중첩문의 순서를 바꿔본다

먼저 아이디가 일치하는지 체크를 한 뒤 admin일시 버튼을 생성하는 방법

(userId === props.userID) ? this.buttonCreate(props) :
(userId === 'admin') ?
this.buttonCreate(props)
: ''}

똑같이 에러가 난다.. 삼항 중첩문이 문제...

🗝  A

a

a

 

 

'에러 모음집' 카테고리의 다른 글

Integer ID 값 API Spring으로 넘길때 오류  (0) 2022.01.10