-
Notifications
You must be signed in to change notification settings - Fork 5
[FE] userInfo를 불러오는 과정에서의 중복코드 줄이기 #933
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
Conversation
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.
정리 감사합니다~ 이 외에도 불필요한 코드 정말 많을텐데 여유가 된다면 날 잡아서 코드 다이어트 한 번 더 하고 싶네요ㅋㅋ
@@ -44,11 +44,3 @@ export const requestGetKakaoLogin = async (code: string) => { | |||
|
|||
return null; | |||
}; | |||
|
|||
export const requestGetUserInfo = async () => { |
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.
감사합니다~ 이거 기억으론 웨디와 제가 서로 이 api가 필요하여 각자 작성했던 것으로 기억해요.
지우는 것을 깜빡하고 있었는데 정리 감사합니다😄😄
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.
이 hook은 제가 작성했었는데 #869 에 적어 놓은 이유였습니다.
이 당시에는 useRequestGetUserInfo가 suspenseQuery가 아니라 일반 query 였던 것으로 기억합니다. 그래서 별도로 작성했는데 동일해졌다면 중복된 파일이 있을 필요 없다는 것에 동의합니다.
@@ -1,5 +1,5 @@ | |||
import Image from '@components/Design/components/Image/Image'; | |||
import useRequestGetUserInfo from '@hooks/queries/auth/useRequestGetUserInfo'; | |||
import useRequestGetUserInfo from '@hooks/queries/user/useRequestGetUserInfo'; |
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.
확실히 user information이니 auth 보다는 user가 더 좋네요
@@ -29,8 +30,7 @@ const SectionContainer = ({children}: React.PropsWithChildren) => { | |||
}; | |||
|
|||
const UserInfoSection = () => { | |||
const {userInfo} = useRequestSuspenseGetUserInfo(); | |||
const {profileImage, nickname} = userInfo; | |||
const {nickname, profileImage} = useUserInfoContext(); |
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.
앗 그렇군요 마이 페이지 상위에서 context로 값을 가져오고 있다면 지워도 좋을 것 같아요!
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.
같은 부분을 작업하다보니 유사한 코드가 반복된 것 같네요 흑흙 섬세하게 살펴봐주어서 감사해용!~~
* refactor: requestGetUserInfo가 user와 auth에서 중복적으로 존재하여 auth에 존재하는 함수 삭제 * refactor: useRequestSuspenseGetUserInfo 삭제 및 useUserInfoContext를 활용하여 userInfo 불러오는 것으로 변경 * chore: useRequestGetUserInfo을 hooks/queries/auth에서 user로 위치 변경 --------- Co-authored-by: JinHo Kim <[email protected]>
issue
구현 사항
requestGetUserInfo 중복 함수 삭제
위 함수는 request/auth와 request/user에 완전히 동일한 형태로 각각 존재했습니다.
해당 함수가 2개 존재할 필요는 없다고 판단하여 request/auth에 존재하던 requestGetUserInfo는 제거해줬습니다. 따라서 requestGetUserInfo 함수는 request/user에 1개만 존재합니다.
useRequestSuspenseGetUserInfo 삭제
useRequestGetUserInfo와 useRequestSuspenseGetUserInfo는 매우 유사하게 생긴 함수입니다.
useRequestGetUserInfo 코드
useRequestSuspenseGetUserInfo 코드
두 코드를 나란히 비교하면 한 눈에 알 수 있습니다.
useRequestSuspenseGetUserInfo 함수로 동작하려는 것을 useRequestGetUserInfo 사용을 통해 대체할 수 있습니다. 따라서 useRequestSuspenseGetUserInfo는 불필요하다고 판단하여 해당 함수를 삭제했습니다.
MyPage의 userInfo 불러오는 방식 변경
useRequestSuspenseGetUserInfo는 MyPage.tsx에서만 사용하고 있었습니다. 그러나 useRequestSuspenseGetUserInfo가 사라지면서 userInfo를 불러오는 방식을 변경해야 했습니다.
useRequestGetUserInfo
는 userInfo를 Context로 제공하는 Provider와 함께 사용하기 위해 제작된 hook입니다. 부모 컴포넌트에서 Provider를 통해 userInfo를 제공하고, 자식 컴포넌트는 Context를 통해 userInfo에 접근할 수 있습니다.이에 따라 MyPage 컴포넌트에서는 userInfo를 직접 불러오는 방식에서 Context를 활용해 userInfo를 받아오는 방식으로 변경했습니다.
이를 통해 userInfo를 Context로 받아서 사용하는 다른 myPage의 하위 페이지들과 동일한 방식으로 userInfo를 받아와 코드의 통일성을 향상시킬 수 있습니다.
useRequestGetUserInfo 파일 위치 auth→user로 변경
앞서 진행한 requestGetUserInfo 중복 함수를 삭제하고 request/user에만 존재하도록 변경한 일로 인해, useRequestGetUserInfo의 위치를 hooks/queries/auth에서 hooks/queries/user로 이동했습니다.
이를 통해 requestGetUserInfo와 useRequestGetUserInfo의 위치가 user로 동일하게 되어 추후 코드를 관리하는 것에 있어 통일성을 주게 됩니다.
🫡 참고사항