What is NgRx?
NgRx is a library for managing state in Angular applications. It is based on the Redux idea: all state is stored in one place and changes only through special events called actions.
Simply put
- Store - a large object that holds all the state (for example, the user, the cart, settings).
- Actions - commands like "Add to cart" or "Load user".
- Reducers - functions that define how the state changes after each command.
- Selectors - for conveniently reading the parts of the store you need (for example, just the user's name).
- Effects - for working with the server: if something needs to be loaded from an API, an effect listens for the action and makes the request.
Example
You click "log out" → a logout action is dispatched → the reducer clears the user in the store → the component receives the new state → Angular re-renders it.
When NgRx is needed
- many different pieces of state,
- there is asynchronous logic (API calls),
- you need to clearly understand what changes, where, and when.
If the project is small, NgRx can be overkill. But if the data is complex and depends on many components, it provides order and control.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.