Open History to see the last commit
1import React, { useState } from 'react'
2import { usePosts } from '../../hooks/usePosts'
3β
4export const PostList = () => {
5 const [postCount, setPostCount] = useState(10)
6 const { data, isLoading, isFetching } = usePosts(postCount)
7β
8 if (isLoading) return <div>Loading</div>
9β
10 return (
11 <section>
12 <ul>
13 {data?.map((post, index) => (
14 <li key={post.id}>
15 <div>
16 <span>{index + 1}. </span>
17 <a href="#">{post.title}</a>
18 </div>
19 </li>
20 ))}
21 </ul>
22 {postCount <= 90 && (
23 <button
24 onClick={() => setPostCount(postCount + 10)}
25 disabled={isFetching}
26 >
27 {isFetching ? 'Loading...' : 'Show More'}
28 </button>
29 )}
30 <style jsx>{`
31 section {
32 padding-bottom: 20px;
33 }
34 li {
35 display: block;
36 margin-bottom: 10px;
37 }
38 div {
39 align-items: center;
40 display: flex;
41 }
42 a {
43 font-size: 14px;
44 margin-right: 10px;
45 text-decoration: none;
46 padding-bottom: 0;
47 border: 0;
48 }
49 span {
50 font-size: 14px;
51 margin-right: 5px;
52 }
53 ul {
54 margin: 0;
55 padding: 0;
56 }
57 button:before {
58 align-self: center;
59 border-style: solid;
60 border-width: 6px 4px 0 4px;
61 border-color: #ffffff transparent transparent transparent;
62 content: '';
63 height: 0;
64 margin-right: 5px;
65 width: 0;
66 }
67 `}</style>
68 </section>
69 )
70}