cloudflare/vinext
Publicmirrored from https://github.com/cloudflare/vinextAvailable
examples/hackernews/lib/fetch-data.ts
19lines · modecode
| 1 | import { cache } from 'react' |
| 2 | import 'server-only' |
| 3 | |
| 4 | const fetchData = cache(async (type: string) => { |
| 5 | const res = await fetch( |
| 6 | `https://hacker-news.firebaseio.com/v0/${type}.json`, |
| 7 | { |
| 8 | next: { |
| 9 | revalidate: 10 |
| 10 | } |
| 11 | } |
| 12 | ) |
| 13 | if (res.status !== 200) { |
| 14 | throw new Error(`Status ${res.status}`) |
| 15 | } |
| 16 | return res.json() |
| 17 | }); |
| 18 | |
| 19 | export default fetchData; |
| 20 | |