Open History to see the last commit
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))
12}
13β
14export { usePosts, fetchPosts }