MCPcopy Create free account
hub / github.com/TanStack/router / fetchPost

Function fetchPost

examples/solid/basic-solid-query-file-based/src/posts.tsx:11–25  ·  view source on GitHub ↗
(postId: string)

Source from the content-addressed store, hash-verified

9export class PostNotFoundError extends Error {}
10
11export const fetchPost = async (postId: string) => {
12 console.info(`Fetching post with id ${postId}...`)
13 await new Promise((r) => setTimeout(r, 500))
14 const post = await axios
15 .get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
16 .then((r) => r.data)
17 .catch((err) => {
18 if (err.status === 404) {
19 throw new PostNotFoundError(`Post with id "${postId}" not found!`)
20 }
21 throw err
22 })
23
24 return post
25}
26
27export const fetchPosts = async () => {
28 console.info('Fetching posts...')

Callers 1

postQueryOptionsFunction · 0.90

Calls 3

infoMethod · 0.65
catchMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected