/
index.jsx
49 lines (45 loc) · 1.16 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useState } from "react";
import Head from "next/head";
import getStories from "../lib/getStories";
import Page from "../components/Page";
export async function getStaticProps() {
const posts = await getStories("frontstories");
return { props: { posts } };
}
export default function Home({ posts }) {
const [pageCount, setpageCount] = useState(1);
const pages = [];
for (let i = 0; i < pageCount; i++) {
pages.push(
<Page
page={i + 1}
category="frontstories"
initialData={i + 1 !== 1 ? null : posts}
key={i}
/>
);
}
return (
<>
<Head>
<title>Hackernews Redesign - A HN client built on top of Next.js</title>
<meta
property="og:image"
content="/hn-redesign.png"
/>
</Head>
<div className="lg:col-span-2 mt-8">
<span className="main-title flex items-center text-soft-black">
<h1 className="fancy-undeline">Top stories</h1>
</span>
{pages}
<button
className="more-btn"
onClick={() => setpageCount(pageCount + 1)}
>
Load more
</button>
</div>
</>
);
}