1. What is Redux?
Answer: Redux is a predictable state management library for JavaScript apps, commonly used with React. It stores the entire application state in a single JavaScript object called the store. Components read from the store and dispatch actions to update it.
2. What are the core principles of Redux?
Answer:
- Single Source of Truth: State is stored in a single object.
- State is Read-Only: You can’t directly modify state—only through actions.
- Pure Functions: Reducers are pure functions that return new state based on action.
3. What is a store in Redux?
Answer:
The store holds the entire app state and provides methods to access (getState()), update (dispatch()), and listen (subscribe()) to state changes.
import { createStore } from "redux";
const store = createStore(reducer);4. What is an action in Redux?
Answer:
An action is a plain JS object that has a type field and optionally a payload.
It describes what happened, not how the state should change.
{ type: 'INCREMENT', payload: 1 }5. What is a reducer?
Answer: A reducer is a pure function that takes the previous state and an action, then returns the new state. It must be pure (no side effects).
function counter(state = 0, action) {
if (action.type === "INCREMENT") return state + 1;
return state;
}6. How do you update state in Redux?
Answer: By dispatching an action to the store. The reducer handles the action and returns a new state.
store.dispatch({ type: "INCREMENT" });7. What is combineReducers?
Answer:
Redux allows splitting reducers into smaller functions and combining them with combineReducers.
Each reducer manages its own slice of state.
import { combineReducers } from "redux";
const rootReducer = combineReducers({ auth: authReducer, user: userReducer });8. What is dispatch() in Redux?
Answer:
dispatch() sends an action to the reducer to update the state.
It’s the only way to trigger a state change in Redux.
store.dispatch({ type: "LOGIN_SUCCESS" });9. How do you access state in Redux?
Answer:
Use store.getState() or in React use useSelector() hook.
const counter = useSelector((state) => state.counter);10. What is middleware in Redux?
Answer:
Middleware intercepts dispatched actions before they reach reducers.
Useful for logging, async operations, or modifying actions.
Example: redux-thunk, redux-logger.