feat: 06-StarRating 구현 (이경하)#26
Open
k0nghaa wants to merge 3 commits into
Open
Conversation
hyun-june
approved these changes
Jun 22, 2026
Contributor
There was a problem hiding this comment.
isFilled 값에 따라 SVG 전체를 조건부 렌더링하기보다는, className이나 fill 값만 조건부로 변경하면 코드 중복을 줄일 수 있을 것 같습니다.
현재는 채워진 별과 빈 별의 SVG 구조가 거의 동일해서, 공통 SVG는 한 번만 작성하고 달라지는 속성만 분기해도 좋을 것 같습니다!
Comment on lines
+36
to
+47
| <> | ||
| {starArray.map((_, index) => ( | ||
| <button | ||
| key={index} | ||
| onClick={() => handleFilledStar(index)} | ||
| onMouseEnter={() => handleMouseEnter(index)} | ||
| onMouseLeave={handleMouseLeave} | ||
| > | ||
| <Star isFilled={index < activeRating} /> | ||
| </button> | ||
| ))} | ||
| </> |
Contributor
There was a problem hiding this comment.
현재는 빈태그로 별 목록만 반환하고 있어, App.tsx에서 사용할 때마다 레이아웃을 위한 wrapper를 따로 작성해야 할 수도 있을 것 같습니다.
StarRating 자체가 하나의 UI 단위라면 내부에서 div나 ul 같은 컨테이너를 제공하는 방식도 고려해보시면 좋을 것 같습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 과제 요약
💡 설계 및 고민한 부분
📖 학습한 내용 및 어려웠던 점 (선택)
머릿속으로는 쉽게 그려졌는데 막상 코드로 구현하려니 어렵네요 🥲
잘못 생각했던 부분이나 막힌 부분을 공유해보려 합니다.
1. 배열이 아닌 컴포넌트를 전달받은
maxStar값에 맞춰 렌더링해야한다.Array.from({ length: maxStar })을 사용해maxStar에 맞는 빈 배열을 만들어map메서드를 사용할 수 있었습니다.2. 토글 구현처럼 (
setIsFilledStar((prev) => !prev);) 값을 반전하는 방식을 사용한다.index < clickedRating)3. 호버(isHovered)와 클릭(isFilled) 값을 Star에 따로 넘겨준다.
isHoveredStar !== null)인지를 기준으로 호버 상태와 클릭 상태를 정하게 되고 해당 상태와 index를 비교해<Star />의isFilled로 전달합니다.❓ 질문 사항 (선택)
현재 채워진 별의 수와그리고 평점이 바뀔 때마다 새 값으로 호출되는 콜백은 사용하지 못했는데, 혹시 다들 사용하셨는지 궁금합니다 ..!📸 스크린샷 (선택)