mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
20 lines
375 B
TypeScript
20 lines
375 B
TypeScript
import { cache } from 'react'
|
|
import 'server-only'
|
|
|
|
const fetchData = cache(async (type: string) => {
|
|
const res = await fetch(
|
|
`https://hacker-news.firebaseio.com/v0/${type}.json`,
|
|
{
|
|
next: {
|
|
revalidate: 10
|
|
}
|
|
}
|
|
)
|
|
if (res.status !== 200) {
|
|
throw new Error(`Status ${res.status}`)
|
|
}
|
|
return res.json()
|
|
});
|
|
|
|
export default fetchData;
|