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

index.js

16 lines410 Bytes

1import ky from 'ky-universal'
2import { useQuery } from '@tanstack/react-query'
3​
4const fetchPosts = async (limit = 10) => {
5 const parsed = await ky('https://jsonplaceholder.typicode.com/posts').json()
6 return parsed.filter((x) => x.id <= limit)
7}
8​
9const usePosts = (limit) => {
10 return useQuery({
11 queryKey: ['posts', limit],
12 queryFn: () => fetchPosts(limit),
13 })
15​
16export { usePosts, fetchPosts }