MCPcopy Index your code
hub / github.com/TanStack/query / Post

Function Post

examples/solid/default-query-function/src/index.tsx:104–137  ·  view source on GitHub ↗
(props: { postId: number; setPostId: Setter<number> })

Source from the content-addressed store, hash-verified

102}
103
104function Post(props: { postId: number; setPostId: Setter<number> }) {
105 // You can even leave out the queryFn and just go straight into options
106 const state = useQuery<any>(() => ({
107 queryKey: [`/posts/${props.postId}`],
108 enabled: !!props.postId,
109 }))
110
111 return (
112 <div>
113 <div>
114 <a onClick={() => props.setPostId(-1)} href="#">
115 Back
116 </a>
117 </div>
118 <Switch>
119 <Match when={!props.postId || state.status === 'pending'}>
120 Loading...
121 </Match>
122 <Match when={state.status === 'error'}>
123 <span>Error: {(state.error as Error).message}</span>
124 </Match>
125 <Match when={state.data !== undefined}>
126 <>
127 <h1>{state.data.title}</h1>
128 <div>
129 <p>{state.data.body}</p>
130 </div>
131 <div>{state.isFetching ? 'Background Updating...' : ' '}</div>
132 </>
133 </Match>
134 </Switch>
135 </div>
136 )
137}
138
139render(() => <App />, document.getElementById('root') as HTMLElement)

Callers

nothing calls this directly

Calls 1

useQueryFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…