File size: 1,558 Bytes
1e92f2d |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import React, { useState } from 'react'
import { usePosts } from '../hooks/usePosts'
export const PostList = () => {
const [postCount, setPostCount] = useState(10)
const { data, isPending, isFetching } = usePosts(postCount)
if (isPending) return <div>Loading</div>
return (
<section>
<ul>
{data?.map((post, index) => (
<li key={post.id}>
{index + 1}. {post.title}
</li>
))}
</ul>
{postCount <= 90 && (
<button
onClick={() => setPostCount(postCount + 10)}
disabled={isFetching}
>
{isFetching ? 'Loading...' : 'Show More'}
</button>
)}
<style jsx>{`
section {
padding-bottom: 20px;
}
li {
display: block;
margin-bottom: 10px;
}
div {
align-items: center;
display: flex;
}
a {
font-size: 14px;
margin-right: 10px;
text-decoration: none;
padding-bottom: 0;
border: 0;
}
span {
font-size: 14px;
margin-right: 5px;
}
ul {
margin: 0;
padding: 0;
}
button:before {
align-self: center;
border-style: solid;
border-width: 6px 4px 0 4px;
border-color: #ffffff transparent transparent transparent;
content: '';
height: 0;
margin-right: 5px;
width: 0;
}
`}</style>
</section>
)
}
|