Skip to main content

What does Action do?

Action in NgRx is simply an object that says: "something happened".

It does not perform the action itself and does not change the state - it only describes the event.

Example

ts
{ type: '[Auth] Login Success', user: { id: 1, name: 'Maria' } }

In this object:

  • type - a required field that states what exactly happened
  • everything else - any data needed for processing

When is Action used

  1. The component calls:
ts
this.store.dispatch(login({ email, password }));
  1. This action goes into the system. It can be "heard" by:
  • reducer - if the state needs to be updated
  • effect - if something side-effecting needs to happen (for example, an API request)

Examples of actions

  • [User] Load Profile
  • [Cart] Add Item
  • [Auth] Logout Success

Conclusion

Action is like a telegram: "this happened, here's the data." NgRx then decides on its own what to do with it.

Short Answer

Interview ready
Premium

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