Open History to see the last commit
1import { notFound } from '@tanstack/react-router'
2import axios from 'redaxios'
3β
4export type PostType = {
5 id: string
6 title: string
7 body: string
8}
9β
10export const fetchPost = async (postId: string) => {
11 console.info(`Fetching post with id ${postId}...`)
12 await new Promise((r) => setTimeout(r, 500))
13 const post = await axios
14 .get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
15 .then((r) => r.data)
16 .catch((err) => {
17 if (err.status === 404) {
18 throw notFound()
19 }
20 throw err
21 })
22β
23 return post
24}
25β
26export const fetchPosts = async () => {
27 console.info('Fetching posts...')
28 await new Promise((r) => setTimeout(r, 500))
29 return axios
30 .get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts')
31 .then((r) => r.data.slice(0, 10))
32}