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 |
Tags
- json-server
- 항해99
- 테코테코
- JavaScript
- C++
- axios
- Python
- sw expert academy
- 리액트
- redux
- redux-saga
- 자바
- Get
- useDispatch
- createSlice
- 항해플러스
- react-redux
- react
- Algorithm
- 매일메일
- maeil-mail
- 이코테
- 코딩테스트합격자되기
- programmers
- 알고리즘
- redux-toolkit
- 프로그래머스
- react-router
- SW
- java
Archives
- Today
- Total
Binary Journey
[React][CRUD] 게시판 만들기 All in One - (refactoring.1) Extract this nested ternary operation into an independent statement. 본문
React/게시판만들기 v2.
[React][CRUD] 게시판 만들기 All in One - (refactoring.1) Extract this nested ternary operation into an independent statement.
binaryJournalist 2021. 5. 13. 16:33반응형
목차 돌아가기:
https://binaryjourney.tistory.com/pages/ReactCRUD-create-board-tutorial-v2
sonarlint extension을 사용해서 자꾸 빨간 줄이 그어져 있는 게 신경쓰여서 해결하려 한다.
원래 views/Article.js 에 작성일시 부분은 이렇게 되어있었다.
<div><span>작성일시: </span><span>{(article.insertDate) ? new Date(article?.insertDate).toLocaleString() : ""}</span></div>
sonarlint warning? error? problem 으로는 다음과 같은 문장이 떴는데
Extract this nested ternary operation into an independent statement.
삼항연산자 아무데서나 쓰지마!!! 이런 느낌이라 말을 듣기로 했음
그래서 그냥 null이나 undefined 인 경우 아예 렌더링 되지 않도록 바꿨다.
<div><span>작성일시: </span><span>{(article?.insertDate) && new Date(article.insertDate).toLocaleString()}</span></div>
Board와 ArticleList 에서도 같은 problem warning이 일어나는데
다음 글을 읽고 그 부분은 고치지 않고 두기로 하였다, stupid하다는 의견에 동의한다,
https://stackoverflow.com/questions/46272156/how-can-i-avoid-nested-ternary-expressions-in-my-code
That being said, you should disable [no-nested-ternary] in your linter. It's kind of stupid that your linter thinks that nested conditionals are bad.
목차 돌아가기:
https://binaryjourney.tistory.com/pages/ReactCRUD-create-board-tutorial-v2
반응형