Skip to content

Commit 7aeca8f

Browse files
authored
Update React Query example (#1244)
1 parent e90632b commit 7aeca8f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

docs/src/content/docs/openapi-fetch/examples.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,15 @@ function useUser({ params, body, reactQuery }: UseQueryOptions<paths[typeof GET_
201201
params.path.user_id,
202202
// add any other hook dependencies here
203203
],
204-
queryFn: () =>
205-
client
206-
.get(GET_USER, {
207-
params,
208-
// body - isn’t used for GET, but needed for other request types
209-
})
210-
.then((res) => {
211-
if (res.data) return res.data;
212-
throw new Error(res.error.message); // React Query expects errors to be thrown to show a message
213-
}),
204+
queryFn: async ({ signal }) => {
205+
const { data, error } = await client.get(GET_USER, {
206+
params,
207+
// body - isn’t used for GET, but needed for other request types
208+
signal, // allows React Query to cancel request
209+
});
210+
if (res.data) return res.data;
211+
throw new Error(res.error.message); // React Query expects errors to be thrown to show a message
212+
},
214213
});
215214
}
216215

0 commit comments

Comments
 (0)