[React][CRUD] 게시판 만들기 All in One - (refactoring.1) Extract this nested ternary operation into an independent statement.
목차 돌아가기:
https://binaryjourney.tistory.com/pages/ReactCRUD-create-board-tutorial-v2
[React][CRUD] create-board-tutorial-v2
* 인용시 출처 부탁드립니다. 완성 소스 code: github.com/cruellaDev/react-create-board-v2 cruellaDev/react-create-board-v2 updated version of react-create-board. Contribute to cruellaDev/react-create-..
binaryjourney.tistory.com
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
How can I avoid nested ternary expressions in my code?
I have code like this. How can I write it in cleaner, more elegant way using functional programming in JavaScript? I want to get rid of nested ternary expressions. Any ideas? props => ({ ...
stackoverflow.com
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
[React][CRUD] create-board-tutorial-v2
* 인용시 출처 부탁드립니다. 완성 소스 code: github.com/cruellaDev/react-create-board-v2 cruellaDev/react-create-board-v2 updated version of react-create-board. Contribute to cruellaDev/react-create-..
binaryjourney.tistory.com