Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

data.ts

23 lines586 Bytes

1import type { Post } from './types'
2​
3export const getPosts = async (
4 limit: number,
5 customFetch: typeof fetch = fetch,
6) => {
7 const response = await customFetch(
8 'https://jsonplaceholder.typicode.com/posts',
9 )
10 const data = (await response.json()) as Post[]
11 return data.filter((x) => x.id <= limit)
13​
14export const getPostById = async (
15 id: number,
16 customFetch: typeof fetch = fetch,
17): Promise<Post> => {
18 const response = await customFetch(
19 `https://jsonplaceholder.typicode.com/posts/${id}`,
20 )
21 const data = (await response.json()) as Post
22 return data