ecyrbe / zodios-react

React hooks for zodios
MIT License
64 stars 12 forks source link

Passing `AbortSignal` down to `axios` request config #178

Closed justblender closed 2 years ago

justblender commented 2 years ago

As it currently stands, it doesn't seem like @zodios/react passes down signal provided by react-query's query function down to axios request config.

react-query doesn't enforce an opinion on whether or not you should use abort signals while handling asynchronous state, but given the fact that this library works exclusively with HTTP requests I think it makes sense to pass signal as a sensible default or at least provide a way for users to specify whether or not queries should be cancelled.

See this: https://tanstack.com/query/v4/docs/guides/query-cancellation.

ecyrbe commented 2 years ago

Hello @justblender ,

I agree with this feature request, i'm going for the same way tRPC handle this (just a little better) as in tRPC their solution will override user defined signal.

So the solution is to add a a signal combinator and also an option to opt in into this feature that is called shouldAbortOnUnmount.
Here is how to activate it:

cons client = new Zodios(api);
const hooks = new ZodiosHooks('my api', client, { shouldAbortOnUnmount: true } );

it's now available on version v10.4.0 of @zodios/react

justblender commented 2 years ago

Wow, that was fast. Thank you!