From e23fbb5f4153479b508391401f6791b0ddf44457 Mon Sep 17 00:00:00 2001 From: Jihoo Kim Date: Fri, 4 Aug 2023 06:22:16 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=8A=A4=ED=81=AC=EB=A1=A4=20=EB=B3=B5?= =?UTF-8?q?=EC=9B=90=20=EB=B2=84=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/user/SelectMyPostType.tsx | 5 ----- src/hooks/useScrollRestoration.tsx | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/components/user/SelectMyPostType.tsx b/src/components/user/SelectMyPostType.tsx index a1be4eff..8b0e098d 100644 --- a/src/components/user/SelectMyPostType.tsx +++ b/src/components/user/SelectMyPostType.tsx @@ -1,7 +1,4 @@ -import { useSetAtom } from 'jotai'; - import { PostType } from '@/pages/user/UserPage'; -import { scrollRestorationAtom } from '@/states/scroll-restoration'; interface SelectMyPostTypeProps { postType: PostType; @@ -14,8 +11,6 @@ export default function SelectMyPostType({ switchPostType, postingCount, }: SelectMyPostTypeProps) { - const setScrollRestoration = useSetAtom(scrollRestorationAtom); - return (
{['내 게시글', '참여한 게시글'].map((label) => { diff --git a/src/hooks/useScrollRestoration.tsx b/src/hooks/useScrollRestoration.tsx index 281e12e1..3e645662 100644 --- a/src/hooks/useScrollRestoration.tsx +++ b/src/hooks/useScrollRestoration.tsx @@ -11,6 +11,13 @@ export default function useScrollRestoration( ); const ref = useRef(null); + useEffect(() => { + setScrollRestoration((prevScrollRestoration) => ({ + ...prevScrollRestoration, + [key]: 0, + })); + }, []); + useEffect(() => { if (!ref.current) return; @@ -19,16 +26,10 @@ export default function useScrollRestoration( const height = ref.current.scrollTop; - if (!scrollRestoration) { - setScrollRestoration({ - [key]: height, - }); - } else { - setScrollRestoration((prevScrollRestoration) => ({ - ...prevScrollRestoration, - [key]: height, - })); - } + setScrollRestoration((prevScrollRestoration) => ({ + ...prevScrollRestoration, + [key]: height, + })); }; ref.current.addEventListener('scroll', handleScroll);