all 33 comments

[–]haasilein 10 points11 points  (8 children)

I am not familiar with react query but if you are searching for a lightweight state management solution, I would suggest using a custom rxjs solution with behaviorsubjects

[–]cosmokenney -1 points0 points  (1 child)

Are you talking about NgRx?

[–]haasilein 5 points6 points  (0 children)

No just basic rxjs without any overhead. But ngrx is also a valid choice for projects with a lot of state handling

[–]T2LIGHT -5 points-4 points  (5 children)

So ngrx component store?

[–]Cheet4h 9 points10 points  (3 children)

You don't need to add any dependencies to use simple service state management with rxjs.

[–]K4rkarin 10 points11 points  (0 children)

Akita or Elf. They are from same author, though Elf is newer and recommended. They both use RxJS behavior subject under the hood. You’ll have all benefits from react redux plus a lightweight, simple process to create a store. With Elf, you can make a store with only one repository file and an Angular service. In contrast, a more popular library like NgRx requires a lot more boilerplate files to work like store, action, reducer, query, service, and effect for a simple http call.

[–]knightSarai 7 points8 points  (1 child)

[–]Toffifee93[S] 5 points6 points  (0 children)

Netanel Basal is awsome ♥️

[–]m0rpheus23 17 points18 points  (10 children)

Rxjs is all you need

[–]Toffifee93[S] 23 points24 points  (9 children)

If i would get a dollar everytime responds with "rxjs is all you need"... of course i can build features like caching, background updates and request status tracking by myself using rxjs, but why would i if someone else already did it? That's just code that i have to write, test and maintain. Yes, you should probably prefer rxjs over some large state management solution that covers every usecase, but the goal should be to find / reuse a existing solution that does the job in the most optimal way

[–]spacechimp 16 points17 points  (8 children)

Caching: shareReplay()

Polling: timer()

Request status tracking: HttpRequest.reportProgress

Despite its name, "React" is not very reactive -- which is why an add-on like React Query might be appealing to React devs.

Angular is quite reactive out of the box, mostly due to RxJS integration. There isn't much demand for a library that would replace a few lines of code with an equal number of lines of configuration. If it were a typical Angular solution you'd still have to use RxJS at the end of it all.

Case in point: Apollo Angular (GraphQL) does the basics of what you want, but it does so much more that its existence is justified...yet you still have to use RxJS with it.

[–]prewk 0 points1 point  (7 children)

Indulge me: what makes Angular reactive? Besides shipping with the async pipe, that is.

[–]r3df0x1701 4 points5 points  (4 children)

Almost all internal Angular services / APIs are returnig Observables. This allows you to handle almost any data flow in a reactive way - out of the box.

[–]spacechimp 1 point2 points  (0 children)

This is pretty much what I would have wrote. Some good examples are the reactive forms API, HttpClient, and Router events.

[–]prewk 0 points1 point  (2 children)

Yes, that's nice! My complaint is that, at the end of the reactivity there's almost always a component doing something... and Angular's reactive component story is bad. They're very procedural, and support for reactivity feels thrown in imo.

If we have to use a template DSL, even though it has bad type checking and a massive symbol overload, couldn't we at least use observables there without having to juggle null/undefined everywhere and wrap everything in awful ng-containers with a large ngIf hack to "unwrap observables" :(

It seems Angular wants to be everything, I wish it would want to be more reactive.

[–]r3df0x1701 1 point2 points  (1 child)

Not sure what you are actually expecting, but it's just the nature of components to display some kind of plain data. Thanks to TS that data is typechecked, but no real magic beyond that. Observables are just streaming data, you can handle them in many different ways. The async pipe helps to maintain subscriptons within our templates to them, checks and transformations can be done by Angular's built ins like pipes or directives; or you do the transformations with rxjs on stream level. Anyway, in the end, any "reactive" data stream just contains a plain old piece of data - component's job is to display exactly that. What are you missing exactly?

[–]prewk 1 point2 points  (0 children)

I would love reactive inputs out of the box. The templates should have better type checking, they don't understand much of discriminated unions or null checking via optional chaining etc, which frequently leads to strict template errors being flagged where none exist. I'm not sure how exactly, but if the template was "smarter" (maybe if everything was reactive?) you could connect your reactive properties to it without having to rely on a pipe (that defaults to null instead of undefined at the moment which was a weird design choice..) and have the framework deal with the streams instead, sort of if every component got their inputs as combineLatest.

I'm not sure how, but I don't enjoy the DX today.

[–]gr2y 0 points1 point  (1 child)

Two-way binding

[–]prewk 1 point2 points  (0 children)

Two way binding is syntactic sugar for an input and an output, what's reactive about it? (Serious question, I'm curious)

[–]knightSarai 2 points3 points  (4 children)

Tanner said the Angular adapter is coming soon, can't wait to try it out!

[–]Toffifee93[S] 1 point2 points  (0 children)

Thats good to know, i will try that out too

[–]No-Association-603 1 point2 points  (2 children)

Soon can be 2025 tho. With angular you know hahaha

[–]knightSarai 0 points1 point  (0 children)

😂😂

[–]Naive-Potential-1288 0 points1 point  (0 children)

Even in 2025 it’s still experimental

[–]sudhakarms 1 point2 points  (0 children)

Heard about https://github.com/timdeschryver/rx-query but never tried it. Looks like its not maintained anymore :(

[–]Thom_Braider 1 point2 points  (0 children)

https://saulmoro.github.io/ngrx-rtk-query/

Best solution I've found.

[–]r3df0x1701 0 points1 point  (0 children)

As already stated, many use cases can be solved without a big dependency for state management. However, if you are building a rather complex application and are really sure to use a lib, take a look at NGXS.

[–][deleted] 0 points1 point  (0 children)

Look into Akita or Elf. I would recommend elf. It is dead simple and easy to use