From fec9eeac1cde7d1b1bf4f0739f59d9c8d8a95863 Mon Sep 17 00:00:00 2001 From: najitwo Date: Sat, 26 Oct 2024 23:11:14 +0900 Subject: [PATCH] feat: implement prefetching for boards --- components/boards/BoardList.tsx | 4 ++-- pages/boards.tsx | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/boards/BoardList.tsx b/components/boards/BoardList.tsx index d9f44af3..887bc9b4 100644 --- a/components/boards/BoardList.tsx +++ b/components/boards/BoardList.tsx @@ -11,8 +11,8 @@ import sortIcon from "@/public/ic_sort.svg"; import Container from "../layout/Container"; import { ArticleProps } from "@/types/articleTypes"; -const BoardList = () => { - const [boards, setBoards] = useState([]); +const BoardList = ({ initialBoards }: { initialBoards: ArticleProps[] }) => { + const [boards, setBoards] = useState(initialBoards); const [order, setOrder] = useState("recent"); const router = useRouter(); const { keyword } = router.query; diff --git a/pages/boards.tsx b/pages/boards.tsx index 74663ad1..a03057be 100644 --- a/pages/boards.tsx +++ b/pages/boards.tsx @@ -1,11 +1,24 @@ import BestBoards from "@/components/boards/BestBoards"; import BoardList from "@/components/boards/BoardList"; +import { fetchData } from "@/lib/fetchData"; +import { ArticleProps } from "@/types/articleTypes"; -const Boards = () => { +export const getStaticProps = async () => { + const BASE_URL = "https://panda-market-api.vercel.app/articles"; + const { list } = await fetchData(BASE_URL); + + return { + props: { + initialBoards: list, + }, + }; +}; + +const Boards = ({ initialBoards }: { initialBoards: ArticleProps[] }) => { return ( <> - + ); };