Function
createPost
(postId: Accessor<number>)
Source from the content-addressed store, hash-verified
| 117 | } |
| 118 | |
| 119 | function createPost(postId: Accessor<number>) { |
| 120 | return useQuery(() => ({ |
| 121 | queryKey: ['post', postId()], |
| 122 | queryFn: async () => { |
| 123 | const { post } = await request<{ post: Post }>( |
| 124 | endpoint, |
| 125 | gql` |
| 126 | query { |
| 127 | post(id: ${postId()}) { |
| 128 | id |
| 129 | title |
| 130 | body |
| 131 | } |
| 132 | } |
| 133 | `, |
| 134 | ) |
| 135 | |
| 136 | return post |
| 137 | }, |
| 138 | enabled: !!postId(), |
| 139 | })) |
| 140 | } |
| 141 | |
| 142 | function Post(props: { postId: number; setPostId: Setter<number> }) { |
| 143 | const state = createPost(() => props.postId) |
Tested by
no test coverage detected
Used in the wild real call sites across dependent graphs
searching dependent graphs…