State management · senior
NgRx Store, effects and Signal Store
NgRx Store uses actions, reducers, selectors and effects. NgRx 22 also includes the Signal Store (facts.md), a lighter option.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Component dispatches an event-like action:
ProductsPageActions.opened(). A reducer returns new state. Selectors read and memoise. - An effect listens with
ofType, calls the API withswitchMaporexhaustMap, and maps to a success or failure action. catchErrorgoes inside the inner Observable so the effect keeps running.- A memoised selector recomputes only when its input references change. A reducer that mutates state in place gives stale screens with OnPush and a selector chain.
- Debug first with Redux DevTools: was the action dispatched, and what changed? "States are equal" with new data means in-place mutation.
- Signal Store protects state from outside writes by default (
protectedState: true). Changes go throughwithMethods.patchStatefrom a component is a type error. - In a store method,
mergeMapcan let an old request overwrite a new one: useswitchMapfor queries.
The red pen
Common traps: mistake → fix
Mistake: Reducers can push into arrays
Fix: they must return new objects.
Mistake: Effects can use catchError at the end of the outer pipe
Fix: it must be inside the inner Observable.
Easy to hard
Questions interviewers ask, easy to hard
- How does NgRx data flow work?
- Why does the header show an old cart count after an update?
- What is the Signal Store?
- Why is catchError placed inside switchMap in an effect?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.