Set up NgRx state management with actions, reducers, and effects
✓Works with OpenClaudeYou are an Angular architect specializing in NgRx state management patterns. The user wants to set up a complete NgRx store with actions, reducers, effects, and selectors for a feature module.
What to check first
- Run
ng versionto confirm Angular CLI is installed (requires Angular 12+) - Verify NgRx is installed:
npm list @ngrx/store @ngrx/effects @ngrx/store-devtools - Check that your feature module exists:
ls src/app/your-feature/
Steps
- Install NgRx packages:
npm install @ngrx/store @ngrx/effects @ngrx/store-devtools @ngrx/entity - Create an actions file at
src/app/store/actions/feature.actions.tswith action types and creators usingcreateAction() - Define your state interface in
src/app/store/reducers/feature.reducer.tswith an initial state object - Implement the reducer function using
createReducer()withon()handlers for each action - Create effects class in
src/app/store/effects/feature.effects.tsusing@Effect()decorator and Observable operators likeswitchMap()orconcatMap() - Register effects with
EffectsModule.forFeature([FeatureEffects])in your feature module - Add selectors using
createFeatureSelector()andcreateSelector()insrc/app/store/selectors/feature.selectors.ts - Dispatch actions in components via
store.dispatch(actionCreator())and subscribe to selectors withstore.select(selectFeature)
Code
// src/app/store/actions/todos.actions.ts
import { createAction, props } from '@ngrx/store';
export const loadTodos = createAction('[Todos Page] Load Todos');
export const loadTodosSuccess = createAction(
'[Todos API] Load Todos Success',
props<{ todos: Todo[] }>()
);
export const loadTodosFailure = createAction(
'[Todos API] Load Todos Failure',
props<{ error: string }>()
);
export const addTodo = createAction(
'[Todos Page] Add Todo',
props<{ title: string }>()
);
// src/app/store/reducers/todos.reducer.ts
import { createReducer, on } from '@ngrx/store';
import * as TodosActions from '../actions/todos.actions';
export interface Todo {
id: number;
title: string;
completed: boolean;
}
export interface TodosState {
todos: Todo[];
loading: boolean;
error: string | null;
}
export const initialState: TodosState = {
todos: [],
loading: false,
error: null
};
export const todos
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Angular Skills
Other Claude Code skills in the same category — free to download.
Angular Component
Create Angular components with inputs, outputs, and lifecycle hooks
Angular Service
Build Angular services with dependency injection and HTTP client
Angular Routing
Configure Angular routing with guards, resolvers, and lazy loading
Angular Forms
Build reactive forms with validation and custom validators
Angular RxJS
Use RxJS operators for async data flows in Angular
Angular Testing
Write Angular unit tests with Jasmine and Karma
Angular Signals State Management
Use Angular Signals for reactive state without RxJS complexity
Angular RxJS Best Practices
Use RxJS operators correctly to avoid memory leaks and subscription bugs
Want a Angular skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.