0
0
Angularframework~5 mins

Actions and reducers pattern in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an action in the Actions and reducers pattern?
An action is a simple object that describes what happened in the app. It usually has a type property and may carry extra data called payload.
Click to reveal answer
beginner
What role does a reducer play in state management?
A reducer is a pure function that takes the current state and an action, then returns a new state. It decides how the state changes based on the action.
Click to reveal answer
intermediate
Why should reducers be pure functions?
Reducers must be pure to ensure predictable state changes. They should not modify inputs or cause side effects like API calls or random values.
Click to reveal answer
intermediate
How do actions and reducers work together in Angular's state management?
Actions describe events, and reducers listen to these actions to update the state accordingly. This keeps state changes clear and traceable.
Click to reveal answer
advanced
What is a common pattern to organize actions and reducers in Angular apps?
Use @ngrx/store library to define actions with createAction and reducers with createReducer. This helps keep code clean and maintainable.
Click to reveal answer
What does an action object usually contain?
AA UI component
BOnly the new state
CA function to update state
DA type and optional payload
What must a reducer function NOT do?
AReturn a new state
BModify the current state directly
CUse the action to decide state changes
DBe a pure function
In Angular, which library is commonly used for actions and reducers?
ARxJS
BAngular Material
C@ngrx/store
DNgBootstrap
What is the main benefit of using actions and reducers?
AEasier to track and manage state changes
BFaster UI rendering
CAutomatic API calls
DSimplifies CSS styling
Which of these is NOT part of the actions and reducers pattern?
AServices
BReducers
CState
DActions
Explain how actions and reducers work together to manage state in an Angular app.
Think about how a message (action) tells the app what changed, and the reducer decides how to update the state.
You got /4 concepts.
    Describe why reducers must be pure functions and what could go wrong if they are not.
    Consider what happens if a function changes data outside itself or depends on random values.
    You got /4 concepts.