Framework guidesReact axios vs tanstack-fetch for TanStack Query
Replace axios unwrap glue with tanstack-fetch — FetchProvider, useFetch, useSse, React Query, refresh-token, migrate CLI, and a full side-by-side comparison.
Read the postOctober 12, 2026 · Angular · TanStack Query · HTTP

Stack
Angular 17+ · tanstack-fetch/angular · @tanstack/angular-query-experimental
Angular’s HttpClient returns cold Observables. TanStack Angular Query wants a Promise that resolves to data, rejects on failure and stops when its AbortSignal fires — so every call gets wrapped in lastValueFrom and an error mapper.
That gap shows up as unwrap-.data helpers, RxJS subscriptions that fight Query’s cache, and interceptors that reinvent refresh-token single-flight. tanstack-fetch closes it with the same client every other stack already uses — wired through Angular DI and signals.
| If you need… | Prefer |
|---|---|
Drop into injectQuery / injectMutation | tanstack-fetch |
Typed FetchError with status + body | tanstack-fetch |
SSE with Authorization + resume | tanstack-fetch/sse + useSse |
| Classic Angular apps with heavy RxJS pipes | HttpClient is fine |
| One HTTP client shared with React/Vue/Solid | tanstack-fetch |
npm install tanstack-fetch @tanstack/angular-query-experimentalHttpClient speaks Observables. TanStack Query speaks Promises + AbortSignal. Bridging them is possible — and noisy.
Contract that matters for Query:
HttpResponse)isError works)signal throughapi.get<User[]>('/users', { signal }) does all three. http.get(...).pipe(map(r => r.body)) asks you to remember them.
import { HttpClient } from '@angular/common/http'
import { inject } from '@angular/core'
import { injectQuery } from '@tanstack/angular-query-experimental'
import { firstValueFrom } from 'rxjs'
export class UsersHttpComponent {
private readonly http = inject(HttpClient)
readonly users = injectQuery(() => ({
queryKey: ['users'],
queryFn: async ({ signal }) => {
// firstValueFrom + manual abort wiring
const request = this.http.get<User[]>('/api/users')
const sub = new AbortController()
signal.addEventListener('abort', () => sub.abort())
return firstValueFrom(request) // often forgets AbortSignal entirely
},
}))
}Common cracks: forgetting signal, returning the whole HttpResponse, catching errors that Query should own.
import { Component } from '@angular/core'
import { injectFetch } from 'tanstack-fetch/angular'
import { injectQuery } from '@tanstack/angular-query-experimental'
import { isFetchError } from 'tanstack-fetch'
@Component({
selector: 'app-users',
template: `
@if (users.isPending()) {
<p>Loading…</p>
} @else if (users.isError()) {
<p>{{ errorLabel() }}</p>
} @else {
<ul>
@for (user of users.data(); track user.id) {
<li>{{ user.name }}</li>
}
</ul>
}
`,
})
export class UsersComponent {
private readonly api = injectFetch()
readonly users = injectQuery(() => ({
queryKey: ['users'],
queryFn: ({ signal }: { signal: AbortSignal }) => this.api.get<User[]>('/users', { signal }),
}))
errorLabel = () => {
const error = this.users.error()
return isFetchError(error) ? `${error.status}: ${error.message}` : 'Error'
}
}No .data unwrap. Failures throw FetchError. Cancel is free if you forward signal.
import { bootstrapApplication } from '@angular/platform-browser'
import { provideHttpClient } from '@angular/common/http' // optional legacy
import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
import { createFetch } from 'tanstack-fetch'
import { createAuthInterceptor } from 'tanstack-fetch/plugins'
import { provideFetchClient } from 'tanstack-fetch/angular'
import { AppComponent } from './app.component'
const api = createFetch({
baseUrl: 'https://api.example.com',
interceptors: [createAuthInterceptor({ getToken: () => localStorage.getItem('access_token') })],
})
bootstrapApplication(AppComponent, {
providers: [
provideFetchClient({ client: api }),
provideTanStackQuery(new QueryClient()),
// keep HttpClient only while migrating modules
// provideHttpClient(),
],
})injectFetch() reads the FETCH_CLIENT token. If you forget provideFetchClient, you get a clear error instead of a silent undefined.
You can also pass { client } into useSse without DI — useful for SSE-only islands.
Rough relative boilerplate for the same features (lower is better). Not a benchmark — a map of where teams spend time.
tanstack-fetchtypical HttpClient path
| Capability | tanstack-fetch | Angular HttpClient |
|---|---|---|
Returns body for Query queryFn | Yes | Adapt (firstValueFrom + map) |
| Throws typed error with status/body | FetchError + isFetchError | HttpErrorResponse |
Native AbortSignal | First-class | Manual / limited |
Status handlers 401–429 | createStatusInterceptor | Custom interceptor |
| Refresh token single-flight | Plugin | Custom |
Path params typing :id | Yes | Manual |
| Upload + progress | api.upload() (tanstack-fetch/sse) | Yes |
SSE + Authorization | tanstack-fetch/sse | Not built-in |
| Angular signals SSE | useSse | DIY |
| tRPC transport | tanstack-fetch/trpc | DIY |
RxJS operators / HttpContext | Via bridge | Native |
| Bundle (HTTP core) | 3.68KB gzip | Framework-included |
import { createFetch } from 'tanstack-fetch'
import {
createAuthInterceptor,
createRefreshTokenInterceptor,
createStatusInterceptor,
} from 'tanstack-fetch/plugins'
let expiresAt = 0
const api = createFetch({
baseUrl: '/api',
interceptors: [
createAuthInterceptor({ getToken: () => localStorage.getItem('access_token') }),
createStatusInterceptor({
401: async () => {
// optional: redirect to login once refresh fails
},
}),
],
})
api.use(
'refresh-token',
createRefreshTokenInterceptor({
refresh: async () => {
const body = await api.post<{ accessToken: string; expiresIn: number }>('/auth/refresh', {
interceptors: { eject: ['refresh-token', 'auth'] },
})
localStorage.setItem('access_token', body.accessToken)
expiresAt = Date.now() + body.expiresIn * 1000
},
before: {
getExpiresAt: () => expiresAt,
skewMs: 60_000,
},
after: { enabled: true },
}),
)HttpClient teams usually encode the same flow as a multi-file interceptor with a shared BehaviorSubject queue. The plugin keeps one in-flight refresh and retries the failed call.
import { injectMutation, injectQueryClient } from '@tanstack/angular-query-experimental'
import { injectFetch } from 'tanstack-fetch/angular'
export class CreateUserComponent {
private readonly api = injectFetch()
private readonly queryClient = injectQueryClient()
readonly createUser = injectMutation(() => ({
mutationFn: (input: CreateUserInput) => this.api.post<User>('/users', { body: input }),
onSuccess: () => {
void this.queryClient.invalidateQueries({ queryKey: ['users'] })
},
}))
}Browser EventSource cannot set Authorization. tanstack-fetch/sse streams over fetch, so cookies or Bearer tokens work.
import { Component } from '@angular/core'
import { createFetch } from 'tanstack-fetch/sse'
import { useSse } from 'tanstack-fetch/angular'
const live = createFetch({
baseUrl: '/api',
plugins: ['sse-resume'],
getToken: () => localStorage.getItem('access_token'),
})
@Component({
selector: 'app-orders-live',
template: `
<p class="status">{{ status() }}</p>
@if (error(); as err) {
<p class="error">{{ err.message }}</p>
}
<pre>{{ data() | json }}</pre>
<button type="button" (click)="close()">Stop</button>
`,
})
export class OrdersLiveComponent {
private readonly stream = useSse<OrderEvent>('/orders/stream', { client: live })
readonly data = this.stream.data
readonly status = this.stream.status
readonly error = this.stream.error
readonly close = this.stream.close
}Status model matches React/Vue/Solid: connecting | connected | disconnected | error.
useSse hooks DestroyRef so the stream closes when the component is destroyed.
import { createTRPCClient, httpBatchLink } from '@trpc/client'
import { createTRPCFetch } from 'tanstack-fetch/trpc'
import { injectQuery } from '@tanstack/angular-query-experimental'
import { injectFetch } from 'tanstack-fetch/angular'
import type { AppRouter } from './server'
export class PostsComponent {
private readonly api = injectFetch()
private readonly trpc = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: '/api/trpc',
fetch: createTRPCFetch(this.api),
}),
],
})
readonly posts = injectQuery(() => ({
queryKey: ['posts'],
queryFn: ({ signal }: { signal: AbortSignal }) =>
this.trpc.post.list.query(undefined, { signal }),
}))
}Auth headers, refresh-token, and status handlers apply to tRPC the same way they apply to REST.
# scaffold Angular + Query options from axios-shaped code
npx tanstack-fetch migrate --from axios --framework angular --write
# health check leftovers
npx tanstack-fetch doctor --dir ./src--framework angular writes something like src/app/api.ts plus query-option helpers aimed at @tanstack/angular-query-experimental.
Suggested migration order:
createFetch client + provideFetchClientinjectQuery first (highest Query win)HttpClient only where RxJS pipelines are still the productsrc/app/
api.ts # createFetch singleton
app.config.ts # provideFetchClient + provideTanStackQuery
queries/
users.query.ts # queryOptions factories
features/
users/
users.component.ts # injectFetch + injectQuery
live/
orders-live.component.ts # useSse// src/app/api.ts
import { createFetch } from 'tanstack-fetch'
import { createAuthInterceptor } from 'tanstack-fetch/plugins'
export const api = createFetch({
baseUrl: '/api',
interceptors: [createAuthInterceptor({ getToken: () => localStorage.getItem('access_token') })],
})// src/app/queries/users.query.ts
import { queryOptions } from '@tanstack/angular-query-experimental'
import { api } from '../api'
export const usersQueryOptions = queryOptions({
queryKey: ['users'] as const,
queryFn: ({ signal }) => api.get<User[]>('/users', { signal }),
})tanstack-fetchHttpClient may staytanstack-fetch/sse + useSsecreateFetch across packagesprovideFetchClient({ client: api }) in app.config / bootstrapqueryFn / mutationFn forwards { signal }isFetchError when you need statustanstack-fetch/sse (not bare EventSource) when auth mattersnpx tanstack-fetch doctor --dir ./src clean before mergenpm install tanstack-fetch @tanstack/angular-query-experimental
npx tanstack-fetch migrate --from axios --framework angular --write
npx tanstack-fetch doctor --dir ./srcSame deep-dive format for every stack:
Framework guides·3 min read
Replace axios unwrap glue with tanstack-fetch — FetchProvider, useFetch, useSse, React Query, refresh-token, migrate CLI, and a full side-by-side comparison.
Framework guides·3 min read
Use tanstack-fetch with Solid — FetchProvider, useFetch, useSse signals, Solid Query, refresh-token, migrate CLI, and comparison graphs.
Framework guides·3 min read
Replace ofetch and axios glue in Vue 3 with tanstack-fetch — createFetchPlugin, useFetch, useSse, Vue Query, refresh-token, and a full comparison.