MCPcopy Create free account
hub / github.com/TanStack/query / Post

Function Post

examples/solid/basic-graphql-request/src/index.tsx:87–114  ·  view source on GitHub ↗
(props: { postId: string; setPostId: Setter<string | null> })

Source from the content-addressed store, hash-verified

85}
86
87function Post(props: { postId: string; setPostId: Setter<string | null> }) {
88 const state = useQuery(() => postsQueries.detail(props.postId))
89
90 return (
91 <div>
92 <div>
93 <a onClick={() => props.setPostId(null)} href="#">
94 Back
95 </a>
96 </div>
97 <Switch>
98 <Match when={state.status === 'pending'}>Loading...</Match>
99 <Match when={state.status === 'error'}>
100 <span>Error: {(state.error as Error).message}</span>
101 </Match>
102 <Match when={state.data !== undefined}>
103 <>
104 <h1>{state.data?.title}</h1>
105 <div>
106 <p>{state.data?.body}</p>
107 </div>
108 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
109 </>
110 </Match>
111 </Switch>
112 </div>
113 )
114}
115
116const root = document.getElementById('root')
117if (!root) throw new Error('Missing #root element')

Callers

nothing calls this directly

Calls 2

useQueryFunction · 0.90
setPostIdMethod · 0.45

Tested by

no test coverage detected