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