cloudflare/vinext

Public

mirrored from https://github.com/cloudflare/vinextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
23f9e1e13decb3ee024adc6a091b9252427f8e2e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/hackernews/lib/fetch-data.ts

19lines · modecode

1import { cache } from 'react'
2import 'server-only'
3
4const 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
19export default fetchData;
20