Skip to main content

What does Effect do?

Effect in NgRx is an action listener that reacts to them and performs side effects, for example:

  • sends an HTTP request,
  • writes to localStorage,
  • dispatches new actions based on the result.

It does not change the state directly. It simply "hears" the action and does something asynchronous.

Example:

  1. The user clicks "log in":
ts
this.store.dispatch(login({ email, password }));
  1. The Effect "hears" this action:
ts
login$ = createEffect(() => this.actions$.pipe( ofType(login), switchMap(action => this.authService.login(action.email, action.password).pipe( map(user => loginSuccess({ user })), catchError(() => of(loginFailure())) ) ) ) );
  1. It calls authService.login(...), waits for the response, and dispatches loginSuccess or loginFailure.

What Effect does:

  • reacts to actions,
  • runs async operations (API calls, timers, requests),
  • sends new actions with the results.

Conclusion: Effect is the connecting link between actions and the outside world. If you need to step outside the store, it's always through it.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.