Skip to content

Commit

Permalink
feat: implement prefetching for boards
Browse files Browse the repository at this point in the history
  • Loading branch information
najitwo committed Oct 26, 2024
1 parent 23bb578 commit fec9eea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/boards/BoardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions pages/boards.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<BestBoards />
<BoardList />
<BoardList initialBoards={initialBoards} />
</>
);
};
Expand Down

0 comments on commit fec9eea

Please sign in to comment.