-
Notifications
You must be signed in to change notification settings - Fork 0
6회차 과제 - 류승현 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
6회차 과제 - 류승현 #2
Conversation
| { | ||
| id: 1, | ||
| picture: thumbnail1, | ||
| prefer: 1, | ||
| location: "Yesan-gun", | ||
| rate: "4.92", | ||
| dist: "94", | ||
| term: "6월 8일~13일", | ||
| review: "한적한 동네라 오히려 편안했고", | ||
| price: "216,824", | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
각각의 특징이 잘 들어난 변수를 사용해서 이해하기 쉬운 것 같습니다!!
| {card.prefer == 1 && ( | ||
| <span className="absolute top-4 left-3 bg-white text-black font-bold text-base px-3 py-1.5 rounded-full"> | ||
| 게스트 선호 | ||
| </span> | ||
| )} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== 비교 보다는 === 비교를 사용하는 것이 더 정확한 코드를 작성하는 데 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
card.prefer 값이 1인지 확인하여 1일 때에만 span 태그를 보여주는 로직은 정말 좋은 접근인 것 같습니다.
알고 계시겠지만 프로그래밍에서 1은 true의 의미도 갖습니다. 이를 활용해서 card.prefer의 값이 1인지를 명시적으로 확인하지 않고 card.prefer 값만으로도 해당 로직을 구현할 수 있습니다.
React에선 0, null, "" 등이 false값을 가지고 1 또는 일반 숫자들은 true값을 가집니다. 선호도가 없다면 0으로 설정해도 되지만 null 값이나 ""(빈문자열)로 설정하는 것도 좋은 방법이에요.
card.prefer 값만으로 확인하는 방법은 아래와 같습니다.
{card.prefer &&
<span>게스트 선호</span>
}이처럼 card.prefer 값을 활용한다면 더 간결해지고 가독성도 높아집니다. 이게 별 것 아닌 것 같지만 이런 것들이 모여서 유지보수성과 완성도를 높여줍니다. 이후에 과제할 때 참고해서 적용해보시면 좋을 것 같습니다 :)
| {/* 더보기 버튼 */} | ||
| <button className="flex justify-center items-center w-8 h-8 mr-4 border border-gray-200 rounded-full text-base hover:bg-gray-300"> | ||
| {">"} | ||
| </button> | ||
| {/* 필터 버튼 */} | ||
| <button className="flex justify-center items-center w-20 h-10 bg-white border border-gray-200 rounded-xl text-sm hover:bg-gray-300"> | ||
| 필터 | ||
| </button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hover을 사용해서 마우스를 올렸을 때 버튼의 색이 회색으로 바뀌게 하는 것은 좋은 효과인 것 같습니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
태현님 말씀에 동감합니다. hover 기능을 통해 해당 버튼이 버튼임을 UI적으로 보여주어 좋네요. 신경 쓰신 게 보여서 좋은 것 같습니다.
vni911
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 이해가 쉽게 잘 짜인 것 같습니다. 고생하셨습니다!
| <div> | ||
| 게스트 한마디 "<span className="text-black">{card.review}</span>" | ||
| </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
card.review &&를 사용하여 평점이 있을 때만 평점 요소를 렌더링 하는 방법도 있으니 참고하면 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정운님 의견은 실제 프로젝트에서도 자주 사용되는 방식이라서 다음에 과제할 때 적용해보면 좋을 것 같네요!
해당 코드를 card.review && 을 사용한 코드로 보여드리면 아래와 같습니다.
<div>
게스트 한마디
{card.review &&
<span className="text-black">
"{card.review}"
</span>
}
</div>card.review가 존재하면 true, 존재하지 않으면 false를 반환하는 것을 활용한 것입니다.
| <img | ||
| className="w-96 h-96 object-cover mb-2 rounded-3xl" | ||
| src={card.picture} | ||
| /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미지의 크기가 고정되어 옆으로 화면을 늘렸을 때 간격이 벌어져 보이는 현상이 발생합니다.
높이는 고정하되 width를 auto로 두는 것은 어떨까요?
|
꼼꼼하게 잘 구현하신 것 같아요! |
jihyun132
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전반적으로 많이 고민하시고 코드 구현하신 게 느껴지네요~! 과제하느라 수고하셨습니다!
| const boxes = cardInfo.map((card) => ( | ||
| <div> | ||
| <div className="relative"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map함수를 사용하실 때는 가장 바깥에서 감싸고 있는 태그(반환되는 태그)에 key또는 id값을 주어야 합니다. 아래처럼 말이죠 👀
const boxes = cardInfo.map((card) => (
<div key={card.id}>
{/* 내용 */}
</div>
));map 함수는 cardInfo배열의 각 요소에 접근 후 저희가 작성한 코드대로 반환하여 배열에 저장된다고 생각하시면 됩니다.
key 또는 id 값을 주는 이유는 React에게 지금 반환하는 것이 고유한 항목임을 알려주어 React가 각 요소를 효율적으로 식별하고, 변경이 필요한 요소만 빠르게 업데이트할 수 있도록 해주는 역할이기 때문입니다.
만약 key 또는 id 를 제대로 지정하지 않는다면 React는 어떤 항목이 변경되었는지를 알 수 없게 되어 전체 리스트를 다시 렌더링하게 됩니다. 이처럼 여러 번의 렌더링은 성능 저하의 요인이 될 수 있습니다. 그래서 가능하면 고유한 값인 key나 id를 사용하는 것이 좋습니다.
| {card.prefer == 1 && ( | ||
| <span className="absolute top-4 left-3 bg-white text-black font-bold text-base px-3 py-1.5 rounded-full"> | ||
| 게스트 선호 | ||
| </span> | ||
| )} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
card.prefer 값이 1인지 확인하여 1일 때에만 span 태그를 보여주는 로직은 정말 좋은 접근인 것 같습니다.
알고 계시겠지만 프로그래밍에서 1은 true의 의미도 갖습니다. 이를 활용해서 card.prefer의 값이 1인지를 명시적으로 확인하지 않고 card.prefer 값만으로도 해당 로직을 구현할 수 있습니다.
React에선 0, null, "" 등이 false값을 가지고 1 또는 일반 숫자들은 true값을 가집니다. 선호도가 없다면 0으로 설정해도 되지만 null 값이나 ""(빈문자열)로 설정하는 것도 좋은 방법이에요.
card.prefer 값만으로 확인하는 방법은 아래와 같습니다.
{card.prefer &&
<span>게스트 선호</span>
}이처럼 card.prefer 값을 활용한다면 더 간결해지고 가독성도 높아집니다. 이게 별 것 아닌 것 같지만 이런 것들이 모여서 유지보수성과 완성도를 높여줍니다. 이후에 과제할 때 참고해서 적용해보시면 좋을 것 같습니다 :)
신경써서 구현한 부분
Category.jsx
categoryList에 저장하고,map()을 사용해서 배열의 모든 카테고리 항목들이 출력 되도록 만들었습니다.hover기능도 추가했습니다.Cards.jsx
card에서 출력 되어야 할 내용들을cardInfo배열에 저장,map()함수를 통해 배열의 모든 항목들이 출력 되도록 구현했습니다.card속 이미지 위에 출력되는 게스트 선호 여부와 좋아요 아이콘은icons8.com에서 가져온 아이콘을 활용해 출력해주고, 두 아이콘 모두position: absolute를 사용해서 숙소 이미지가 들어있는thumbnail컴포넌트 위에 렌더링되도록 만들었습니다!구조 분석 및 완성본
새롭게 알게 된 내용
질문