Redux MCQ Banner

Redux Multiple Choice Questions (MCQs) and Answers

Master Redux with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Redux. Begin your placement preparation journey now!

Q61

Q61 How do you apply middleware in a Redux store?

A

const store = createStore(rootReducer, applyMiddleware(logger));

B

const store = new Store(rootReducer, middleware);

C

const store = configureStore(middleware);

D

const store = setMiddleware(rootReducer, logger);

Q62

Q62 Given the middleware function below, what will it log? const logger = store => next => action => { console.log('Dispatching:', action.type); return next(action); };

A

Only the action type before it reaches the reducer.

B

The new state after an action is processed.

C

The entire Redux store state.

D

Nothing, as middleware does not log actions.

Q63

Q63 What will happen if next(action) is omitted in middleware?

A

The middleware will log the action twice.

B

The reducer will not receive the action.

C

The Redux store will crash.

D

Middleware will continue execution as normal.

Q64

Q64 Identify the issue in the following middleware: const customMiddleware = store => next => action => { console.log('Action:', action.type); next(action); store.dispatch({ type: 'LOGGED_ACTION' }); };

A

Middleware should not dispatch actions after calling next(action).

B

Middleware must always modify the state directly.

C

Middleware should return undefined.

D

Middleware should not log actions.

Q65

Q65 A Redux application with middleware does not process an action. What is the most likely cause?

A

Middleware is not applied using applyMiddleware.

B

Middleware is modifying the Redux store.

C

The reducer is missing an initial state.

D

Middleware is using store.getState().

Q66

Q66 A developer notices that actions are not reaching the reducer when using middleware. What could be the issue?

A

The middleware does not call next(action).

B

Middleware is logging actions incorrectly.

C

Reducers are mutating the state directly.

D

The Redux store is missing an initial state.

Q67

Q67 A Redux application with async middleware is dispatching multiple actions, but only the first one updates the state. What could be the cause?

A

The middleware is dispatching actions incorrectly.

B

Actions are modifying the state directly.

C

Middleware is calling dispatch without ensuring state updates complete.

D

Reducers are mutating the state.

Q68

Q68 What is Redux Thunk used for?

A

Handling synchronous state updates

B

Executing async logic inside reducers

C

Allowing action creators to return functions instead of action objects

D

Rewriting reducers dynamically

Q69

Q69 Why is Redux Thunk needed in Redux applications?

A

Redux only supports synchronous updates by default.

B

Reducers cannot handle action types.

C

Middleware is required for Redux to work.

D

Redux uses Thunk for debugging.

Q70

Q70 How does a Redux Thunk function typically dispatch actions?

A

It dispatches actions only when the component re-renders.

B

It allows an action creator to return a function that receives dispatch.

C

It replaces reducers with middleware.

D

It prevents the store from updating state.

Q71

Q71 What parameter does Redux Thunk provide to the function returned by an action creator?

A

getState

B

dispatch

C

store

D

Both dispatch and getState

Q72

Q72 What happens if you dispatch a plain object instead of a function while using Redux Thunk?

A

The object is ignored by the store.

B

The action is dispatched normally.

C

Redux throws an error.

D

The reducer modifies the store directly.

Q73

Q73 How do you correctly define an async action using Redux Thunk?

A

const fetchData = () => { return dispatch => { dispatch({ type: 'LOADING' }); fetchData().then(data => dispatch({ type: 'SUCCESS', payload: data })); } };

B

const fetchData = dispatch => { dispatch({ type: 'LOADING' }); fetchData().then(data => dispatch({ type: 'SUCCESS', payload: data })); }

C

const fetchData = () => ({ type: 'FETCH_DATA' });

D

const fetchData = dispatch => dispatch({ type: 'FETCH_DATA' });

Q74

Q74 Given the following code, what is missing? const fetchData = () => { return dispatch => { dispatch({ type: 'REQUEST_STARTED' }); fetch('https://api.example.com/data') .then(response => response.json()) .then(data => dispatch({ type: 'REQUEST_SUCCESS', payload: data })); }; };

A

The initial state is missing.

B

There is no error handling.

C

The reducer is incorrect.

D

Redux Thunk is not installed.

Q75

Q75 What is the purpose of calling dispatch({ type: 'LOADING' }) before making an async API request?

A

To reset the Redux store

B

To indicate that an API request has started

C

To fetch data from the local store

D

To replace the reducer

Q76

Q76 Identify the issue in the following Redux Thunk action: const fetchData = () => dispatch => { fetch('https://api.example.com/data') .then(response => response.json()) .then(data => dispatch({ type: 'FETCH_SUCCESS', payload: data })); };

A

The dispatch function is missing in the returned function.

B

The reducer cannot handle async actions.

C

The function should return a promise.

D

The dispatch function should be passed as an argument.

Q77

Q77 A Redux Thunk action is not updating the state. What could be a possible reason?

A

The reducer is modifying the state directly.

B

The Thunk function is not dispatching an action.

C

Middleware is missing from Redux.

D

Actions cannot modify state.

Q78

Q78 A developer notices that async actions work in development but fail in production. What could be the cause?

A

Redux Thunk is not installed in production.

B

The reducer is not updating the state.

C

Actions are missing a payload.

D

Async actions are only allowed in development.

Q79

Q79 A Redux Thunk action is dispatching multiple times, causing unexpected state changes. What could be the issue?

A

The API response is incorrect.

B

The reducer is mutating state directly.

C

The action creator is dispatching inside a loop without checking conditions.

D

The store is missing middleware.

Q80

Q80 What is the primary purpose of React-Redux?

A

To manage component state

B

To connect Redux state and actions to React components

C

To replace Redux reducers

D

To store React component props globally

Q81

Q81 Which component is used to make the Redux store available to all React components?

A

<StoreProvider>

B

<Provider>

C

<ReduxContainer>

D

<Context>

Q82

Q82 How does a React component access the Redux state?

A

By using useState()

B

By calling store.getState() inside the component

C

By using useSelector() from React-Redux

D

By dispatching an action

Q83

Q83 What does useDispatch() do in a React-Redux component?

A

Connects the component to the Redux state

B

Dispatches actions to the Redux store

C

Replaces the Redux store

D

Fetches data from an API

Q84

Q84 Why is it recommended to use useSelector() instead of accessing store.getState() directly?

A

useSelector() only returns the entire state.

B

Directly calling store.getState() causes unnecessary re-renders.

C

useSelector() memoizes state selections and prevents unnecessary re-renders.

D

store.getState() modifies the Redux store.

Q85

Q85 How do you correctly use useSelector() to get the Redux state in a component?

A

const count = useSelector(state => state.count);

B

const count = store.getState().count;

C

const count = state.useSelector(count);

D

const count = store.count;

Q86

Q86 What is the correct way to connect a class component to Redux using connect()?

A

export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);

B

export default MyComponent(connect(mapStateToProps, mapDispatchToProps));

C

connect(MyComponent)(mapStateToProps, mapDispatchToProps);

D

export default mapStateToProps(connect(MyComponent, mapDispatchToProps));

Q87

Q87 Given the following component, what will happen? const Counter = () => { const count = useSelector(state => state.count); const dispatch = useDispatch(); return (<button onClick={() => dispatch({ type: 'INCREMENT' })}>{count}); };

A

The count will update correctly when clicked.

B

The button will not display the count.

C

The reducer will not update the state.

D

The button click will cause an infinite loop.

Q88

Q88 Identify the issue in the following component: const Counter = () => { const count = useSelector(state => state.count); const dispatch = useDispatch(); return (<button onClick={() => dispatch(increment())}>{count}); };

A

increment() should be defined inside the component.

B

The increment() function should be imported as an action creator.

C

The useDispatch() hook should be inside a useEffect().

D

useSelector() should return a function.

Q89

Q89 A React component does not update when the Redux state changes. What could be a possible reason?

A

The component is missing useEffect().

B

The Redux state is being mutated inside the reducer.

C

The component is missing useState().

D

The Redux store has no actions.

Q90

Q90 A Redux-connected component throws an error saying store is undefined. What could be the issue?

A

The Redux store is not properly provided using .

B

The connect() function is used incorrectly.

C

The useSelector() hook is missing.

D

The component is not using useState().

ad verticalad vertical
ad