State management is one of the most important aspects of any app that has UI. redux is a popular library for maintaining state in the React community. ngrx is a redux-inspired library for maintaining state in Angular apps. But if redux is a rather simple library, ngrx is not so much, and its workflow is illustrated in the diagram below.
In this blog, I’m not going to explain how ngrx works in detail. You can learn it by going through one of the online tutorials, attending our online workshop, or reading the last chapter of our Angular book. I’ll just show you a video comparing two small apps that have the same functionality, but one of them implements state management by using RxJS BehaviorSubject in an Angular service, while the other uses ngrx.
The app that doesn’t use ngrx has about 80 lines of code and its production build size is 268KB. The ngrx version of this app has about 160 lines of code and its production build weighs 315KB.
In short, I do not recommend using ngrx for state management of small and mid-size apps.
Typically, you use a library to write less code, but the current version of ngrx requires you to write more code.
2 thoughts on “Angular: When using ngrx is an overkill”
Hello, what is your opinion on ngxs?
Thank you for this excellent article and explanation. Your tutorials on Angular have been a great help to me