Skip to content

Commit

Permalink
use client for public blog post list for speed up.
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzzystar committed Sep 30, 2024
1 parent b722175 commit 44f166f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions components/PublicBlogList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use client";

import { useState, useEffect } from "react";
import { BlogPost } from "@/lib/githubApi";
import Link from "next/link";

Expand All @@ -13,9 +16,14 @@ export default function PublicBlogList({
posts: BlogPost[];
username: string;
}) {
const sortedPosts = [...posts].sort(
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
);
const [sortedPosts, setSortedPosts] = useState<BlogPost[]>([]);

useEffect(() => {
const sorted = [...posts].sort(
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
);
setSortedPosts(sorted);
}, [posts]);

const groupedPosts = sortedPosts.reduce((acc, post) => {
const year = new Date(post.date).getFullYear();
Expand Down

0 comments on commit 44f166f

Please sign in to comment.