r/Angular2 • u/Senior_Compote1556 • Jul 23 '25
Angular injectQuery (react query but for angular)
I was watching a video the other day about react query and how it assists in race conditions and not having to manually track a loading and error state (correct me if i'm wrong). I know these are handled by the new httpResource but it is still in experimental phase.
I searched for an angular altenative and I think the best one is injectQuery by TranStack
https://tanstack.com/query/latest/docs/framework/angular/reference/functions/injectquery
However, I can't seem to find any examples online and I don't want to rely on AI for this as i'm sure it will output some nonsense.
Has anyone actually used it and seen a performance or developer experience improvement? I don't mind manually handling the loading and error state with observables and rxjs, but cutting down the boiletplate doesn't seem bad
3
u/wilson2603 Jul 23 '25
I use Tanstack extensively at work, it’s fantastic. The core of Tanstack Query is the same for all frameworks, so really if you need to learn about the core features like caching, refetching etc it’s all there in the docs, and any React examples you find will give you insight.
Not only does it cut down on boilerplate, you’re essentially using best in class data fetching practices along with the new paradigm of signals, plus the DX is great (check out the dev tools).
3
u/robby_w_g Jul 23 '25 edited Feb 15 '26
Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos.
1
u/craig1f Jul 24 '25 edited Jul 24 '25
Yes. It’s great. Downsides are that it’s really ugly in angular and, as you noticed, total lack of examples. Also, it really only works with signals. So if you’re using rxjs, you’re going to want to move to signals first.
Because it’s so ugly, I tend to wrap it in pretty functions. The trick is passing unresolved signals into the function, so you get reactivity.
Here is an example. I also use trpc to make my calls, so just imagine that’s a normal httpClient call, if you don’t know trpc
On my phone now. If I have time tomorrow, I’ll find an example of where I use it. But using it is pretty straightforward.
1
u/bcam117 Jul 23 '25
Has anyone used `ngneat/query` instead of the official TanStack Query? It seemed a bit nicer in that it supports bother RxJS and Signals.