39 |
}
42 | isReachingEnd={swr =>
43 | swr.data?.[0]?.length === 0 ||
44 | (swr.data?.[swr.data?.length - 1]?.length ?? 0) < PAGE_SIZE
45 | }
46 | >
47 | {response =>
48 | response?.map(item => {
49 | return (
50 |
60 |
74 |
75 | {item.width} x {item.height}
76 |
77 |
78 | {item.author}
79 |
80 |
81 | {item.url}
82 |
83 |
84 |
85 | )
86 | })
87 | }
88 |
89 |
90 | )
91 | }
92 | Picsum.storyName = 'Picsum (Horizontal Scrolling)'
93 |
--------------------------------------------------------------------------------
/src/components/InfiniteScroll/Reddit.stories.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useSWRInfinite } from 'swr'
3 |
4 | import LoadingIndicator from './LoadingIndicator'
5 | import InfiniteScroll from '.'
6 |
7 | export default {
8 | title: 'InfiniteScroll/Reddit',
9 | component: InfiniteScroll,
10 | }
11 |
12 | interface RedditPost {
13 | subreddit: string
14 | author: string
15 | title: string
16 | thumbnail: string
17 | permalink: string
18 | url: string
19 | }
20 |
21 | interface RedditPostObject {
22 | kind: 't3'
23 | data: RedditPost
24 | }
25 |
26 | interface RedditDataResponse {
27 | after: string
28 | children: RedditPostObject[]
29 | }
30 |
31 | const RedditPostCard: React.FC<{ post: RedditPost }> = ({ post }) => (
32 |