&& operator
기존 자바스크립트에서 삼항연산자의 경우
condition ? ture - return : false- return 이런식으로 condition이 true이면 true일때의 리턴갑슬
false이면 false일때의 리턴값을 보내주는 방식이다. 뭐 중첩도 되고 여러 방향에서 쓰일 수 있다.
그런데~ react를 공부하며 삼항연산자에 && operator를 알게되었는데
true && expression은 항상 expression으로 평가되고 false && expression은 항상 false로 평가된다.
쉽게 말해 true일때만 expression이 실행된다. false라면 그냥 react는 무시한다.
살짝 맛만 보자면
위 코드에서 기본적으로 nowPlaying이 false이면 오른쪽은 아에 실행되지 않는다,
그리고 nowPlaying이 true라도 nowPlaying.length > 0이 false라면 역시
Section은 빈태그만 반환하게 된다.
좋은거 알았다.
여러 조건을 붙일때
if condition
if condition
if condition
이렇게 계속 쓸필요가 없다...
https://blog.logrocket.com/conditional-rendering-in-react-c6b0e5af381e/#andoperator
Conditional rendering in React: 9 methods with examples - LogRocket Blog
Conditional rendering refers to delivering elements & components based on certain conditions. Learn how to do conditional rendering in React.
blog.logrocket.com
여기 보면 좀 더 상세히 기술 되어 있는데 한번 읽어보자.