-
Notifications
You must be signed in to change notification settings - Fork 2
[FE] [06-05] 별글 컴포넌트 구현, 간단한 레이블 디자인 #94
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
Merged
Merged
Conversation
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
- 별글 컴포넌트 생성 - 우선은 서버데이터없이 더미 데이터로 생성, 추후 업데이트 필요
- Emotion 패키지 설치 - @emotion/react, @emotion/styled
- PostStars 컴포넌트에 달려있는 설명 글귀인 Label 컴포넌트의 디자인 변경 - 폴더 구조 확정전까지는 스타일 컴포넌트도 같은 파일에 위치
Collaborator
|
넘흐예쁘네요.. |
bananaba
previously approved these changes
Nov 16, 2023
Collaborator
bananaba
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.
LGTM
KimGaeun0806
previously approved these changes
Nov 16, 2023
bananaba
previously approved these changes
Nov 17, 2023
- useEffect hook에서 Early return 으로 리팩토링
b19f14d
Member
Author
|
@KimGaeun0806 님의 리뷰대로 Early return 적용했습니다. |
bananaba
approved these changes
Nov 19, 2023
KimGaeun0806
approved these changes
Nov 19, 2023
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.
📎 이슈번호
#42
📃 변경사항
사용자의 사진과 글 정보가 존재할
별글 컴포넌트를PostStars라는 이름으로 구현했습니다.PostStars 컴포넌트를 구현하면서 기존에 은하를 구성하는 더미 별들에 달려있던 모든 이벤트는 삭제했습니다. ❌ (onClick 이벤트 등)
PostStars 컴포넌트에 붙어 짧은 설명을 적은 레이블 컴포넌트 디자인을 간단하게 Emotion으로 구현해주었습니다. 현재는 폴더구조가 확정이 되지않아 같은 파일에 존재하지만 폴더구조가 확정이 되면 스타일 컴포넌트는 파일에서 분리하는 것이 좋을듯 합니다.
📌 중점적으로 볼 부분
원래 PostStars 컴포넌트는 서버로부터 전달받은 데이터를 기반으로 생성해야하지만, 현재는 더미데이터로 대체했습니다.
PostStars 컴포넌트는 은하를 구성하는 별 컴포넌트인 Star 컴포넌트를 재활용하는 방식으로 구현했는데, 이제 클릭이벤트 핸들러는 PostStars 컴포넌트에만 필요하므로 Star 컴포넌트에 존재하던 핸들러를 PostStars 컴포넌트로 올리고, props로 핸들러를 전달하는 방식으로 수정했습니다.
이 방식으로 수정할 때의 문제로, 현재 클릭 이벤트 핸들러에서는 Star 컴포넌트의 참조, 즉 ref가 필요한데 핸들러의 위치가 부모 컴포넌트인 PostStars 컴포넌트로 올라오면서 간단히 useRef만 가지고 연결하는 것은 불가능해졌습니다. 따라서 부모컴포넌트에서 생성한 ref를 props로 전달, 자식컴포넌트의 ref와 연결할 수 있게 해주는
forwardRef를 이용했습니다.forwardRef로 Star 컴포넌트를 감싸주고 부모 컴포넌트에서 useRef로 생성한 meshRef를 Star 컴포넌트에 전달, mesh에 ref로 연결해주는 것을 통해 이제 PostStars에서도 Star 컴포넌트의 mesh에 대한 접근을 할 수 있습니다.
문제는 mesh에 대한 접근이 부모 컴포넌트인 PostStars 컴포넌트 뿐만아니라 Star 컴포넌트 자체에서도 useFrame훅을 통해 스케일을 조절하는 곳에서 필요하다는 것입니다. 하지만 이미 mesh에 대한 ref는 부모에게서 props로 전달받은 ref를 연결해주고 있으므로 Star 컴포넌트 자체에서 mesh에 대한 접근을 얻어올 방법이 없어보였는데, 구글링을 통해 방법을 알아냈습니다. 부모에게서 전달받은 ref를 인자로 커스텀 훅인 useForwardRef에 넘겨 자식컴포넌트에서 사용할 ref인 innerRef를 생성, 이제 이를 활용해 자식컴포넌트에서도 mesh에 접근할 수 있습니다.
추후 폴더구조가 확정되면 커스텀 훅은 분리가 필요해보입니다.
mesh에 대한 짧은 설명 글을 화면에 출력하기 위해 drei의 Html 컴포넌트를 활용했습니다. Html 컴포넌트의 children으로 원하는 HTML 태그를 넘기면 그를 캔버스에 그려주는데, 넘길 HTML 태그를 스타일링하면 캔버스에서도 스타일이 적용된 레이블을 볼 수 있습니다. 마찬가지로 추후 폴더구조가 확정되면 스타일 컴포넌트의 위치를 옮겨줄 필요가 있어보입니다.
🎇 동작 화면
2023-11-16.9.14.08.mov
💫 기타사항
facebook/react#24722
useForwardedRef 훅은 위 링크를 참고했습니다.