Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the NgRx Store in Angular?
NgRx Store is a state management library for Angular apps. It helps keep app data in one place, making it easier to manage and share across components.
Click to reveal answer
beginner
How does NgRx Store help with app state?
NgRx Store keeps the app state in a single, immutable object. This means the state can't be changed directly but only through specific actions, making the app predictable.
Click to reveal answer
beginner
What are Actions in NgRx Store?
Actions are simple objects that describe what happened in the app. They tell the store how to update the state.
Click to reveal answer
intermediate
What role do Reducers play in NgRx Store?
Reducers are pure functions that take the current state and an action, then return a new state. They decide how the state changes based on actions.
Click to reveal answer
intermediate
Why is immutability important in NgRx Store?
Immutability means the state object is never changed directly. Instead, a new state object is created on every change. This helps track changes clearly and avoid bugs.
Click to reveal answer
What does the NgRx Store primarily manage in an Angular app?
AApp state
BRouting
CHTTP requests
DComponent templates
✗ Incorrect
NgRx Store manages the app state centrally, making it easier to share and update data.
Which NgRx concept describes an event that triggers state change?
AReducer
BSelector
CEffect
DAction
✗ Incorrect
Actions describe events that tell the store how to update the state.
What must a reducer function always return?
AAn action
BThe same state object
CA new state object
DA component
✗ Incorrect
Reducers return a new state object based on the current state and action.
Why is the state in NgRx Store immutable?
ATo allow direct changes
BTo prevent bugs and track changes clearly
CTo speed up rendering
DTo store UI templates
✗ Incorrect
Immutability helps avoid bugs by ensuring state changes are clear and predictable.
Which of these is NOT part of the NgRx Store pattern?
AComponents
BReducers
CActions
DSelectors
✗ Incorrect
Components are Angular building blocks but not part of the NgRx Store pattern itself.
Explain how NgRx Store manages state in an Angular app.
Think about how data flows and changes in the app.
You got /4 concepts.
Describe the roles of Actions and Reducers in NgRx Store.
Consider who tells the store what happened and who decides how state changes.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of the NgRx Store in an Angular application?
easy
A. To style components with CSS dynamically
B. To handle HTTP requests and responses automatically
C. To keep all application data in one central place for easy access and updates
D. To manage routing between different pages
Solution
Step 1: Understand NgRx Store role
The NgRx Store is designed to hold the application state in one place.
Step 2: Compare with other options
Options B, C, and D describe other Angular features, not the store's purpose.
Final Answer:
To keep all application data in one central place for easy access and updates -> Option C
Quick Check:
NgRx Store = Central app data storage [OK]
Hint: NgRx Store = single source of truth for app data [OK]
Common Mistakes:
Confusing store with routing or HTTP services
Thinking store manages styles or UI directly
2. Which of the following is the correct way to dispatch an action named loadItems using NgRx Store in a component?
easy
A. this.store.call(loadItems);
B. this.store.emit(loadItems);
C. store.dispatch = loadItems();
D. this.store.dispatch(loadItems());
Solution
Step 1: Recall NgRx dispatch syntax
Actions are dispatched by calling this.store.dispatch(action()).
Step 2: Check other options for syntax errors
Options A, B, and C use incorrect methods or assignment instead of dispatch call.
What will be the state after dispatching { type: 'increment' } twice starting from initial state?
medium
A. { count: 0 }
B. { count: 2 }
C. { count: 1 }
D. { count: -2 }
Solution
Step 1: Analyze reducer behavior for 'increment'
Each 'increment' action adds 1 to the current count.
Step 2: Apply two increments starting from 0
0 + 1 = 1 after first increment, then 1 + 1 = 2 after second increment.
Final Answer:
{ count: 2 } -> Option B
Quick Check:
Two increments = count 2 [OK]
Hint: Add 1 per 'increment' action to count [OK]
Common Mistakes:
Counting only one increment
Confusing decrement with increment
4. Identify the error in this NgRx reducer code:
function todoReducer(state = [], action) {
if (action.type === 'add') {
state.push(action.payload);
return state;
}
return state;
}
medium
A. Mutating state directly instead of returning a new state
B. Missing default case in reducer
C. Incorrect action type string
D. Reducer should not return state
Solution
Step 1: Check state mutation
The reducer uses state.push(), which changes the original array directly.
Step 2: Understand NgRx immutability rule
Reducers must return new state objects without mutating the old state.
Final Answer:
Mutating state directly instead of returning a new state -> Option A
Quick Check:
Reducers must be pure and immutable [OK]
Hint: Never mutate state; always return new object/array [OK]
Common Mistakes:
Using push instead of spread operator
Ignoring immutability in reducers
5. You want to create a feature state slice for user profiles using NgRx. Which combination correctly sets up the feature state and selector?
1. Define interface UserProfileState { name: string; age: number; } 2. Create reducer userProfileReducer 3. Register feature state with key 'userProfile' 4. Select user name from store
Which code snippet correctly selects the user name?
hard
A. const selectUserProfile = createFeatureSelector<UserProfileState>('userProfile');
const selectUserName = createSelector(selectUserProfile, state => state.name);
B. const selectUserName = createSelector('userProfile', state => state.name);
C. const selectUserProfile = createSelector('userProfile');
const selectUserName = state => state.name;
D. const selectUserName = createFeatureSelector<UserProfileState>('userProfile').pipe(map(state => state.name));
Solution
Step 1: Understand feature selector usage
Use createFeatureSelector with the feature key to get the feature state.
Step 2: Create selector for user name
Use createSelector with the feature selector and a projector function to select the name.
Final Answer:
const selectUserProfile = createFeatureSelector<UserProfileState>('userProfile');
const selectUserName = createSelector(selectUserProfile, state => state.name); -> Option A