@ngrx/store
Reactive state management for Angular apps built on RxJS — a predictable, unidirectional data flow inspired by Redux.
@ngrx/store
AngularReactive state management for Angular apps built on RxJS — a predictable, unidirectional data flow inspired by Redux.
Fit
Bundle (gzip)
6.0 kB
20.9 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Managing shared state in large Angular apps quickly becomes a nightmare. Services holding mutable data lead to bugs where multiple components modify the same object concurrently, change detection runs unpredictably, and you lose the ability to time-travel debug or replay state transitions. As the app grows, it becomes impossible to trace where a state change originated.
What It Does
@ngrx/store implements the Redux pattern for Angular using RxJS observables. State lives in a single immutable store; components dispatch typed Actions, pure Reducer functions compute the next state, and Selectors derive slices of state for templates. The result is a fully predictable, testable, and debuggable state layer — with DevTools support for inspecting every state transition.
Installation
npm install @ngrx/storeUsage Example
// counter.actions.ts
import { createAction } from '@ngrx/store';
export const increment = createAction('[Counter] Increment');
export const decrement = createAction('[Counter] Decrement');
// counter.reducer.ts
import { createReducer, on } from '@ngrx/store';
import { increment, decrement } from './counter.actions';
export const initialState = 0;
export const counterReducer = createReducer(
initialState,
on(increment, (state) => state + 1),
on(decrement, (state) => state - 1)
);
// app.module.ts
import { StoreModule } from '@ngrx/store';
import { counterReducer } from './counter.reducer';
@NgModule({
imports: [StoreModule.forRoot({ count: counterReducer })],
})
export class AppModule {}
// counter.component.ts
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { increment, decrement } from './counter.actions';
@Component({
selector: 'app-counter',
template: `
<div>Count: {{ count$ | async }}</div>
<button (click)="increment()">+</button>
<button (click)="decrement()">-</button>
`,
})
export class CounterComponent {
count$ = this.store.select((state) => state.count);
constructor(private store: Store<{ count: number }>) {}
increment() { this.store.dispatch(increment()); }
decrement() { this.store.dispatch(decrement()); }
}Related packages
Angular Component Dev Kit — a set of behavior primitives for building accessible, high-quality UI components without prescribing any visual style.
@angular/materialAngularOfficial Material Design component library for Angular — 30+ accessible, themeable UI components built for Angular's ecosystem.
@ng-bootstrap/ng-bootstrapAngularAngular widgets built from scratch using Bootstrap CSS — no jQuery, no Popper.js, just pure Angular components.
ng-zorro-antdAngularEnterprise-grade UI component library for Angular based on Ant Design — 60+ production-ready components with a polished design system.
@ngneat/until-destroyAngularAutomatic RxJS subscription cleanup for Angular components — no more manual unsubscribe logic in ngOnDestroy.