일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- express
- clonecoding
- MongoDB
- JavaScript
- Flutter
- Mongoose
- Component
- API
- CSS
- DART
- pug
- HTML
- Session
- heroku
- nodejs
- react
- 리액트
- CLONE
- javscript
- backend
- NextJs
- ES6
- frontend
- form
- TypeScript
- node.js
- 자바스크립트
- ECMAScript
- graphQL
- GRID
- Today
- Total
Enjoy Programming
&& 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
여기 보면 좀 더 상세히 기술 되어 있는데 한번 읽어보자.
'JavaScript > React' 카테고리의 다른 글
react- 연습 code-sandbox (0) | 2021.07.23 |
---|---|
kind of PropTypes (0) | 2021.06.18 |
[clone coding-devflix] detail container (0) | 2021.06.13 |
[clone coding-devflix] search container (0) | 2021.06.13 |
[clone coding-devflix] container Presenter2 (0) | 2021.06.13 |