Skip to content

Commit e52e51a

Browse files
committed
Refactor: Link페이지 보수 작업
1 parent 81a8d1d commit e52e51a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

hooks/useFetchLinks.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { useEffect } from "react";
2+
import { useRouter } from "next/router";
23
import { proxy } from "@/lib/api/axiosInstanceApi";
34
import { LinkData } from "@/types/linkTypes";
4-
import { ParsedUrlQuery } from "querystring";
55
import useViewport from "./useViewport";
66

77
// 링크 페이지의 query가 바뀌면 그에 맞는 링크들을 보여주는 훅
88
const useFetchLinks = (
99
setLinkCardList: (list: LinkData[], totalCount: number) => void,
10-
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>,
11-
query?: ParsedUrlQuery,
12-
pathname?: string
10+
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>
1311
) => {
12+
const router = useRouter();
13+
const { query, pathname } = router;
1414
const { isTablet } = useViewport();
1515

1616
useEffect(() => {

pages/link/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { GetServerSidePropsContext } from "next";
33
import { useRouter } from "next/router";
44
import { parse } from "cookie";
@@ -86,8 +86,12 @@ const LinkPage = ({
8686
const [folderName] = useFolderName(folder);
8787
const [folderList, setFolderList] = useState(initialFolderList);
8888

89+
useEffect(() => {
90+
setLinkCardList(initialLinkList, initialTotalCount);
91+
}, [initialLinkList, initialTotalCount, setLinkCardList]);
92+
8993
// 링크페이지의 query가 바뀌면 새로운 리스트로 업데이트 해주는 훅
90-
useFetchLinks(setLinkCardList, setIsLoading, router.query, router.pathname);
94+
useFetchLinks(setLinkCardList, setIsLoading);
9195

9296
return (
9397
<>

0 commit comments

Comments
 (0)