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

index.js

14 lines400 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 const result = parsed.filter((x) => x.id <= limit)
7 return result
8}
9​
10const usePosts = (limit) => {
11 return useQuery(['posts', limit], () => fetchPosts(limit))
13​
14export { usePosts, fetchPosts }