hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.24k stars 96 forks source link

Add abort signal to tanstack query queryFn #1189

Open amarant opened 3 hours ago

amarant commented 3 hours ago

Description

Tanstack query can abort the fetch, but it needs to pass the AbortSignal signal prop to the axios or fetch client.

https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation#query-cancellation

It would be great to add this functionality.

mrlubos commented 3 hours ago

Hey @amarant, are you asking for this?

import axios from 'axios'

const query = useQuery({
  queryKey: ['todos'],
  queryFn: ({ signal }) =>
    axios.get('/todos', {
      // Pass the signal to `axios`
      signal,
    }),
})
amarant commented 3 hours ago

exactly

mrlubos commented 3 hours ago

Say no more ✅