Angular MCQs – State Management with RxJS and NgRx

11.) Which function is used to define multiple action handlers inside a reducer?

A) on()
B) handle()
C) reduceState()
D) mapState()

Answer: Option A

Explanation: The on() function associates actions with state changes inside reducers.

12.) How do you add NgRx Store to an Angular app?

A) import { StateModule } from ‘@ngrx/ngrx’;
B) import { NgRxModule } from ‘@angular/core’;
C) import { StoreModule } from ‘@ngrx/store’;
D) import { ReduxModule } from ‘@angular/platform-redux’;

Answer: Option C

Explanation: The StoreModule is used to set up state management in an Angular application.

13.) Which function in NgRx is used to define initial state?

A) createReducer()
B) initializeState()
C) setInitialState()
D) defineState()

Answer: Option A

Explanation: The createReducer() function defines the initial state and state transitions.

14.) What does on() do inside a reducer in NgRx?

A) Handles HTTP requests
B) Binds effects to reducers
C) Configures the NgRx store
D) Defines how actions affect state

Answer: Option D

Explanation: on() is used inside a reducer to map actions to state changes.

15.) What is createEffect() used for in NgRx?

A) To trigger UI animations
B) To trigger UI animations
C) To update local storage
D) To improve API performance

Answer: Option B

Explanation: createEffect() is a function in NgRx that listens for actions and triggers effects like API calls.

16.) What is the purpose of Actions in NgRx?

A) To define UI interactions
B) To create new components dynamically
C) To trigger state changes in the store
D) To manage routing logic

Answer: Option C

Explanation: Actions in NgRx represent user or system events that update the state.

17.) What does StoreModule.forRoot() do in NgRx?

A) Initializes the global store in an Angular application
B) Creates a new Angular module
C) Registers new components dynamically
D) Handles API requests

Answer: Option A

Explanation: StoreModule.forRoot() sets up the NgRx store at the application level.

18.) What is the purpose of createSelector() in NgRx?

A) To generate a new reducer
B) To handle side effects in effects
C) To modify an observable’s behavior
D) To optimize and retrieve specific pieces of state

Answer: Option D

Explanation: createSelector() is used to extract and memoize data from the NgRx store efficiently.

19.) In an NgRx effect, which operator is commonly used to handle asynchronous actions?

A) mergeMap()
B) catchError()
C) finalize()
D) debounceTime()

Answer: Option A

Explanation: mergeMap() allows handling multiple API requests without canceling previous ones.

20.) What is the key advantage of using the NgRx store over Angular services?

A) It prevents the use of observables
B) It offers centralized state management
C) It eliminates the need for HTTP requests
D) It directly modifies the DOM

Answer: Option B

Explanation: The NgRx store centralizes state, making data flow predictable and reducing complexity in large applications.

Leave a Reply

Your email address will not be published. Required fields are marked *