Skip to content

Conversation

@oortmealy
Copy link

✏️ 작업 내용

#️⃣ 39

#39


📷 작업 결과

작업 결과 사진을 업로드해주세요.
영상 노션에 올려놨어용


💡 함께 공유하고 싶은 부분

해당 주차를 공부하면서 함께 이야기하고 싶은 주제를 남겨주세요.

(어려웠던 부분과 해결 과정, 핵심 코드, 참고한 자료 등)
태그로 검색기능 구현이 아직 미비해요.....어렵습니다....


🤔 질문

해당 주차 워크북을 공부하면서 궁금했던 질문들을 남겨주세요.


✅ 워크북 체크리스트

  • 모든 핵심 키워드 정리를 마쳤나요?
  • 핵심 키워드에 대해 완벽히 이해하였나요?
  • 실습/미션을 수행하였나요?

✅ 컨벤션 체크리스트

  • pr 제목을 컨벤션에 맞게 작성하였나요?
  • pr에 해당되는 이슈를 연결하였나요?
  • 적절한 라벨을 설정하였나요?
  • 코드리뷰를 요청하기 위해 reviewer를 등록하였나요?
  • 닉네임/main 브랜치의 최신 상태를 반영하고 있나요?

@oortmealy oortmealy self-assigned this May 22, 2025
@oortmealy oortmealy added the 💡 Mission 미션 수행 label May 22, 2025
Comment on lines 70 to 88
const throttledFetchNext = useThrottle(() => {
if (hasNextPage && !isFetchingNextPage) {
fetchNextPage();
}
}, 1000);

useEffect(() => {
const handleScroll = () => {
if (
window.innerHeight + window.scrollY >=
document.body.offsetHeight - 300
) {
throttledFetchNext();
}
};

window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, [throttledFetchNext]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금은 리렌더링 시 throttledFetchNext가 매번 새 함수를 리턴해, useEffect의 의존성 배열에서 throttledFetchNext가 계속 바뀌게 돼서, 리렌더링마다 handleScroll 이벤트가 제거되고 새로 등록돼요.

이뿐만 아니라, useThrottle 훅 내에서 lastCall.current도 매번 새로 초기화되기 때문에,
쓰로틀링 효과가 나타나지 않아요!

두가지 방법 중 하나 사용하는 걸 추천드립니당

  1. useThrottle로 만든 함수를 useRef(...).current에 저장해서 리렌더링돼도 같은 함수 참조를 유지하기
  2. useThrottle 훅 내에서 useCallback({리턴 함수}, [delay]) as T 로 리턴해 리렌더링 시에도 함수값 유지되게 하기

Copy link

@namgungseok12 namgungseok12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

Copy link

@qowldud qowldud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨씁니당


const [inputValue, setInputValue] = useState(search);
const [searchType, setSearchType] = useState<"title" | "tag">(
searchParams.get("type") === "tag" ? "tag" : "title"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 태그까지는 생각안했어서 이런방식으로 하는거 좋은것같아요!

queryKey: ["search", debouncedSearch, sortOrder, searchType],
queryFn: async ({ pageParam = 0 }) => {
console.log("fetching LPs...");
const res = await api.get("/lps", {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

태그 관련은 api가 /lps/tag여서 안불러와지던 것일까요..?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옹 그런가바여 참고해서 고쳐볼게요!!

@oortmealy oortmealy merged commit 6beafa4 into ozoo/main May 30, 2025
@oortmealy oortmealy deleted the ozoo/#39 branch May 30, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💡 Mission 미션 수행

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants