Skip to the page

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.

The 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 with switchMap or exhaustMap, and maps to a success or failure action.
  • catchError goes 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 through withMethods. patchState from a component is a type error.
  • In a store method, mergeMap can let an old request overwrite a new one: use switchMap for 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

  1. How does NgRx data flow work?
  2. Why does the header show an old cart count after an update?
  3. What is the Signal Store?
  4. 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 voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview