Function
Post
({
postId,
setPostId,
}: {
postId: number
setPostId: React.Dispatch<React.SetStateAction<number>>
})
Source from the content-addressed store, hash-verified
| 90 | } |
| 91 | |
| 92 | function Post({ |
| 93 | postId, |
| 94 | setPostId, |
| 95 | }: { |
| 96 | postId: number |
| 97 | setPostId: React.Dispatch<React.SetStateAction<number>> |
| 98 | }) { |
| 99 | const { status, data, error, isFetching } = usePost(postId) |
| 100 | |
| 101 | return ( |
| 102 | <div> |
| 103 | <div> |
| 104 | <a onClick={() => setPostId(-1)} href="#"> |
| 105 | Back |
| 106 | </a> |
| 107 | </div> |
| 108 | {!postId || status === 'pending' ? ( |
| 109 | 'Loading...' |
| 110 | ) : status === 'error' ? ( |
| 111 | <span>Error: {error.message}</span> |
| 112 | ) : ( |
| 113 | <> |
| 114 | <h1>{data.title}</h1> |
| 115 | <div> |
| 116 | <p>{data.body}</p> |
| 117 | </div> |
| 118 | <div>{isFetching ? 'Background Updating...' : ' '}</div> |
| 119 | </> |
| 120 | )} |
| 121 | </div> |
| 122 | ) |
| 123 | } |
| 124 | function usePosts() { |
| 125 | return useQuery({ |
| 126 | queryKey: ['posts'], |
Callers
nothing calls this directly
Tested by
no test coverage detected