-
Notifications
You must be signed in to change notification settings - Fork 3
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
Hotfix/#218 메들리 기능 이슈 해결 #231
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.
오빠 체고👍👍 보고 배워서 다음에는 이슈없는 알찬 코드를 만들어볼게요😆😎
고생했어용✨✨
@@ -7,9 +8,10 @@ import { PiickleSWRResponse } from "../../../types/remote/swr"; | |||
|
|||
export function useMedleyLists() { | |||
const { data, error } = useSWR<PiickleSWRResponse<MedleyCard[]>>(`${PATH.MEDLEY}`, realReq.GET_SWR); | |||
const randomMedleyLists = useMemo(() => data?.data.data.sort(() => Math.random() - 0.5), [data]); |
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.
궁금한게 있어요😵 이 코드는 data가 변할 때마다, 랜덤함수를 반환하라는 거죠?!
새로고침할 때랑, 카드뷰 들어갔다 나오면 메들리 순서가 변경되는데
data는 구롬 언제 바뀌는지에 대한 코드가 어디있는지 아시나용?-?
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.
@NYeonK
swr에서 언제 데이터가 revalidate 되는지 살펴보면 될 것 같아요!
살펴보고 저도 알려주세요 !!
시간복잡도도 생각하는 그,, 증맬루 멋있다,,⭐ |
📌 내용
mouseDown
할 때부터 화면이 계속 업데이트 됨으로써, 커스텀 훅이 random 함수 계속해서 새롭게 반환시켜줘요. 그래서 클릭 이벤트가 일어나지 않아 프리뷰를 볼 수가 없었어요. 이를useMemo
로 계속해서 변하지 않게끔 막아주었습니다O(n)
) 객체에서 index를 찾아 반환(O(1)
)하는 방식이 효율적일 것 같아 수정하였습니다.